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

Forall Gallery Items Patch to SP List Not Working

Hello,

 

I have been trying to figure out why my gallery items are no longer patching to a new SharePoint list. It's starting to drive me crazy... I am using the expression below but nothing is being created in my new SharePoint list. Any idea why it's no longer working?

 

Information about my gallery:
I am using one combo box and three input fields to collection (using the 'Onselect' on a button) information into a collection on my SharePoint form. Then I have my gallery added within a datacard to default all the collection items within input text fields. When I test the form the gallery is displaying as expected, but when I submit it nothing is being created (patched) to the new SharePoint list. I added my gallery into an existing datacard so it wouldnt move and overlap with the other cards when a user scrolls through the form.

 

Expression I am using within the 'OnSuccess' of my form. 

ForAll(Gallery.Allitems,Patch(SPlist,Defaults(SPlist),{Title: Titleinputfield.text}));ResetForm(Self);RequestHide()

19 REPLIES 19

Hi @Alanisp22 ,

That is hard to answer without seeing your model. What are the gallery Items? I also need to understand how your form interacts with the gallery (you cannot have a form based directly on a collection item)

Hi @Alanisp22 ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz ,

 

Sorry, for the delay. I was out the past week. I appreciate you for still being willing to help. Here is a zoomed-in screenshot of my form and the gallery. My form is tied to my SharePoint list titled "Project Tracker", which is where the top dropdown ("Service" title)  and input columns come from. The add service button was added to a data card and upon clicking, it collects the dropdown selection and all the inputted numbers and adds to my data collection (created in Powerapps). From there, the gallery below (which consists of a dropdown and input fields in case a user needs to come back to the form to edit any data), will display each collection item added. 

Upon saving the form (using the Save button at the very top of the SharePoint form page), the gallery items are added to my second SharePoint list titled "Services".

I have the following listed on my form's OnSuccess field to have the gallery items patched to my second list, which works, but when the user goes back to the form submitted to make edits none of the gallery items are listed to make edits. The gallery is completely blank. I think it's because I have it set to patch the collection items and they are not being saved for some reason. When I check the collection items (view page) in PowerApps nothing is listed there either. 

ForAll(ServiceCollection,Patch(Services,Defaults(Services),{Title:"Hello",Received:Value(ReceivedUnits),Completed:Value(CompletedUnits),Price:Value(Price),ExpectedAmount:Value(ExpectedAmount),ActualAmount:Value(ActualAmount),Service:{Value:ServiceName,Id:ServiceId},Account:{Value:Account,Id:AccountId},InvoiceID:SharePointForm1.LastSubmit.ID}));ResetForm(Self);RequestHide();Reset(Gallery)

Alanisp22_0-1606752311081.png

 

Hi @Alanisp22 ,

I will start with some basic stuff when a Patch is not working - have a look at the alignment of the data types and the input you are providing. So assuming ServiceCollection has some data in it when you run this

   Patch(
      Services,
      Defaults(Services),
      {
         Title:"Hello",
         Received:Value(ReceivedUnits),
         Completed:Value(CompletedUnits),
         Price:Value(Price),
         ExpectedAmount:Value(ExpectedAmount),
         ActualAmount:Value(ActualAmount),
         Service:
         {
            Value:ServiceName,
            Id:ServiceId
         },
         Account:
         { 
            Value:Account,
            Id:AccountId
         },
         InvoiceID:SharePointForm1.LastSubmit.ID
      }
   )
);
ResetForm(Self);
RequestHide();
Reset(Gallery)

what type of fields are Service and Account in your list Services?

@WarrenBelz Service and Account are both Vlookup columns in my Services SP list. I will try to rewrite my input based on this to see if that resolves the issue. 

@WarrenBelz I got the patch to work directly with my gallery with the input you provided instead of my collection so that was perfect! Yay! Thank you!

Now I just have that issue where the last items submitted (saved within my form in the gallery) are not displaying when the listing is reopened ( form reopened to edit). Do you know how I can get my gallery to display what was previously submitted? Is there a way for me to set the gallery's default to pull the previously saved services based on the same issued id number when it's in the edit mode? Maybe using: 

InvoiceID:SharePointForm1.LastSubmit.ID

Hi @Alanisp22 ,

Firstly, you might watch this video from Shane Young @Shanescows and ask yourself why you need the Lookup columns - I have not used them in years.
Assuming your fields are names the same in the collection and the list, this may work

ForAll(
   ServiceCollection As aService,
   Patch(
      Services,
      Defaults(Services),
      {
         Title:"Hello",
         Received:Value(aService.ReceivedUnits),
         Completed:Value(aService.CompletedUnits),
         Price:Value(aService.Price),
         ExpectedAmount:Value(aService.ExpectedAmount),
         ActualAmount:Value(aService.ActualAmount),
         Service:
         {
            '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",            
            Value:aService.Service.Value,
            Id:aService.Service.Id
         },
         Account:
         { 
            '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
            Value:aService.Account.Value,
            Id:aService.Account.Id
         },
         InvoiceID:SharePointForm1.LastSubmit.ID
      }
   )
);
ResetForm(Self);
RequestHide();
Reset(Gallery)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Hi @Alanisp22 ,

Glad you got it working - I was posting while you sent the last item.

LastSubmit() will only work if the record was submitted by the same user in the current session. If you want the newest ID, you need something like

First(
   Sort(
      Services,
      ID,
      Descending
   )
).ID

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz , Thank you for your continued help! For the gallery items, when I patch them into the Service SP list I have the ID number of the submitted form (tied to my 1st SP List) added to them under a general number column "InvoiceID". How can I set my gallery to display those items? In other words, what should I use to display the Service list items in my gallery (within the "edit" view of my form) if I want it pulled based on the patched InvoiceID number that is identical to the submitted form listing in my 1st SP list?

For example, I submitted form ID: 29 to my first SharePoint list "ServiceTracker". Within that form, I added 3 service items to my gallery and they patched successfully into my 2nd SharePoint list "Services" with the InvoiceID: 29. Now I want these items to display in the gallery of the submitted form ID: 29 when I open it to edit. 

 

@WarrenBelz I added my vlookup columns to the patch and used this (with the 'odata.type')  to get those values to patch. So this solution is what I am using to get all my gallery items (including the vlookup columns) to patch perfectly. Thank you!

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 (3,029)