cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Alanisp22
Helper II
Helper II

Gallery Collection Items Disappearing When Form Submitted

Hello,

 

I have a SharePoint form consisting of two screens. The first screen is connected to my SharePoint list "Service Tracker" columns and the second screen consists of text (pulled from screen one data), a drop-down menu for service options, and 3 input fields. Once a user selects a service from the drop-down and then inputs values into the 3 input fields they are added to a collection by clicking on the 'Add Service' button.

The collection items are then listed in the inserted gallery displayed below. The gallery's "Items" is set to my collection name "ServiceCollection", and Upon submission of the form ( once the screen once is filled in and screen two has services added to it) the gallery items are patched to a second SharePoint list "Services".  My issue is that once a user goes back to the previously submitted form to make edits the gallery is completely blank. I need the gallery to display all the previously added services in case a user needs to edit them, delete, or add more. I do see that the patching of these services is working correctly but they are just not appearing in the gallery after submission. Does anyone have a suggestion on how to resolve this?

Additional note, each service added to the gallery is patched to my second SP list "Services" with the ID number of the submitted form to tie them together for reporting.

Gallery items are appearing as expected when the form is being completed:

Alanisp22_2-1607103936676.png

 

 

Gallery is completely blank in the view and edit mode once the form is submitted: 

Alanisp22_3-1607103963311.png

 

 


It appears my collection is being cleared as soon as the form is submitted but I am not sure why. 

17 REPLIES 17
Steveareno
Helper II
Helper II

Greetings, I am having this same issue but I'm afraid I did not understand your reference to the solution. You mention that  "I could not narrow down any code that clears it but I went back to your previous response in my patch issue and used the filter function you mentioned and that worked for me." I did not see a description of this filter function in any previous response. Could you elaborate on how you resolved the issue? 

@Steveareno Hi! To resolve the issue, I duplicated the screen that displayed my gallery. One screen is set to display when the form is in "New" mode and the other identical screen appears when in "Edit" and "View" mode.

 

The new mode screen is set to display any items I patch to a collection by having the gallery's 'Item' set to the collection name. To be specific, when a user clicks the "Add Service" button (after selecting their service type and inputting their received quantity, completed quantity, and price) in the "new" form, that item is patched to a collection, which then appears in the gallery1 within that screen.

 

Once the user saves the form, a new listing is saved in my SharePoint list1 (where the form is based) and the items in the gallery (from the collection) are patched to my second SharePoint list2 with the details, along with the ID number of the SharePoint list1 to link together in the "view"/"edit" screen. I patched it by using the following within the main forms 'OnSuccess' field:


 

ForAll(Gallery1.AllItems,Patch(SPLIST2NAME,Defaults(SPLIST2NAME),{Received:Value(Receivedgallery.Text),Completed:Value(Completedgallery.Text),Price:Value(Pricegallery.Text),InvoiceID:Formname.LastSubmit.ID, Service:

         {

            '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",           

            Value:Service.Selected.Value,

            Id:Service.Selected.Id

         }

}));ResetForm(Self);RequestHide();Refresh('SPLIST2NAME')

 

The @data is for my vlookup column that will display the service name. InvoiceID:Formname.LastSubmit.ID is being used to link all of the gallery items by using the ID number of the listing created in my first SharePoint list1.

 

Then for the "edit" and "view" mode screen, I applied the following filter to gallery2's  "items" (Filter(SPLIST2NAME,(InvoiceID = FormID.Text)). This displays the gallery items from my SPList2 that are tied to the forms SPList1 listing ID number (In other words, it ties the previously submitted gallery1 items.) It's set to FormID.Text because I have the forms issued ID number listed on the top of the screen as general text to reference. 

Thanks for providing that information. I think it will work with my app, but if it's OK I'd like to provide some details about my app so you can maybe help me apply what you've done correctly.

 

I have two lists Drug Screen Master and Drug Screen Subjects. "Master" is where the main form is edited, and Subjects is where the items entered in the Gallery are posted. There is a value "Master ID" that connects each gallery item to the Master item. Below is the Master form with the gallery at the bottom:

 

Master Form.JPG

 

The OnSuccess code for the New form (SharePointForm1) is:

 

ForAll(Subjects, If(!IsBlank(LastName), Patch('Drug Screen Subjects', Defaults('Drug Screen Subjects'), {'Last Name': LastName, 'First Name': FirstName, Email: Email, 'Master ID': SharePointForm1.LastSubmit.ID}))); Refresh('Drug Screen Master'); RequestHide()

 

Do I put the same code in the OnSuccess for SharePointForm1_1? And just change the Items setting for the gallery on SharePointForm1_1 to the filter setting you describe? So that's really the only difference between SharePointForm1 and SharePointForm1_1?

 

 

@Steveareno Are you using the + or 'Save' button to patch the items to your gallery? And are you allowing edits to the items within the gallery for an existing listing?

I did not make a change to my OnSuccess code. In my example, I built the gallery on a second screen, separate from my form. I would expect your app would be fine without requiring any change to the ‘OnSuccess’ code.

Here are the additional changes I made to my second screen:

For my second screen (the "edit"/"view" mode with the filtered gallery), I had the ‘On select’ code for the "Add service" button updated to patch any additional services added to an existing listing to patch directly to my SharePoint list2 (SPLIST2NAME). I did that by applying the following:

Patch(SPLIST2NAME,Defaults(SPLIST2NAME),{ Received:Value(Receivedgallery2_1.Text),Completed:Value(Completegallery2_1.Text),Price:Value(Pricegallery2_1.Text), InvoiceID:DataCardValue6.Text,Service:
{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Value:Service_2.Selected.Value,
Id:Service_2.Selected.Id
}
});Reset(Service_2);Reset(Receivedgallery2_1);Reset(Completegallery2_1);Reset(Pricegallery2_1)

This allows the new service items to appear within the gallery instantly. I do want to point out that I have it set up this way so edits can be made in real-time. If a user was to add more items to the gallery in the edit/view mode screen, they will be patched to the 2nd SharePoint list instantly without requiring them to submit the form. However, if they wanted to make changes to any fields outside the gallery they would need to save the form for those to reflect in the main form listing (on my 1st SharePoint list). This is acceptable on my end since the listing already exists and users are free to delete and re-add to the gallery as needed.

To allow real-time edits within the “edit/view” mode gallery, you will also want to update the ‘OnChange’ field for each input text field within the gallery to have the changes happen instantly to your 2nd SharePoint list (‘Drug Screen Subjects’) by using Patch. For example, I have the following code for my Received input text field displayed in gallery2 of my “edit/view” screen:

Patch(SPLIST2NAME, ThisItem,{Received: Value(Receivedgallery2_1.Text)})

 

I also updated the ‘OnSelect’ for the trash can icon in the “edit/view” mode screen gallery to Remove(SPLIST2NAME, ThisItem). This is so a user can delete the listing from the gallery and 2nd SharePoint list instantly.

Hello, again. I have everything working pretty well, but I'm struggling to get the gallery on the edit screen to filter. Here's the scenario:

 

I have the list that the form is tied to, Drug Screen Master, below:

 

DrugScreenMaster.JPG

The gallery pulls its data from a second list, Drug Screen Subjects, where the Master ID field is the same as the ID of the item on the master list:

 

DrugScreenSubjects.JPG

If I set the gallery on the edit screen to use the Drug Screen Subjects as a data source, it pulls all the items from the list.

Gallery01.JPG

What I want when someone selects the item on the Drug Screen Master to edit is that it displays the gallery items that have its ID as their Master ID. So in the above example, how do I set up the filter on the Items to show the two gallery items associated with the selected Drug Master item?

@Steveareno Hi! Try adding the form's id field to your screen and then set your gallery filter to the following  Filter(Drug Screen Subjects, (MasterID = idfieldname.Text)). You can set the visibility to false if you don't want to show this information to a user. Just make sure you use the exact data card name for the forms ID field and the Master ID column name in the filter code. This will filter the gallery to only show the values with the matching "MasterID".

Steveareno
Helper II
Helper II

Perfect! That did the trick! Thanks so much for all your help.

jainu
Frequent Visitor

Set On Success property of form as  Collect(collection name, Form1.LastSubmit);

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,703)