cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
stgiesbrecht
Level: Powered On

Update multiple SharePoint Items

How do I batch update multiple SharePoint Online list items? I have a screen with a gallery that is displaying one or more items. The collection is built from a filter on the SharePoint list. I have an input field on the gallery that I want the user to be able to input and then click a button to "Save All" and have values that they input saved back to the SharePoint list. On the "Save All", I have tried 

ForAll(colApprovers, Patch(Approvals, {ID: Value(Text(colID))}, {Title: "25 - "&Text(colID)}));

and it seems like only the first selected item in the SharePoint list is getting updated even though there are 3 items listed in the collection and 3 items that match the filter condition.

I want the user to be able to update them all at once rather than an edit and save on each of the gallery items individually.

 

Any thoughts?

 

Thanks,

Scott

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Update multiple SharePoint Items

One last try, it looks like we are getting a little bit further by removing the ID from the values being patched. That makes sense because you shouldn't be able to alter the ID of a list.  Lets try again with a lookup column in the second element of the Patch.  This is assuming that colID is the ID column in colApprovers shown on the left side of your screenshot. Since these are not new items, I would assume that the colID is being carried over from the Approvals list.

ForAll(colApprovers, Patch(Approvals,Lookup(Approvals, ID = colID), {Title: "25 - " & Text(colID)}))

 

15 REPLIES 15
Super User
Super User

Re: Update multiple SharePoint Items

Hi @stgiesbrecht,

You are missing the second element of the Patch() function.  This is the part that tells Patch which record to update.

ForAll(colApprovers, Patch(Approvals,Lookup(Approvals, ID=colID), {ID: Value(Text(colID))}, {Title: "25 - "&Text(colID)}));

Since you did not specify what records you wanted to patch, it only patched the first one.  If this answers your question, please mark the thread as Solved. 

 

See: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch for more details.

 

 

stgiesbrecht
Level: Powered On

Re: Update multiple SharePoint Items

I have updated as suggested to add the Lookup but it is still only updated the first item. My code is the following

ForAll(colApprovers, Patch(Approvals,LookUp(Approvals, ID=Value(Text(colID))), {ID: Value(Text(colID))}, {Title: currentLoop&Text(colID)}));

Also, for some reason "colID" which is numeric, I need to use Value(Text(colID)) in order for it to find and update ID properly, not sure why that is.

 

Thanks, Scott

Super User
Super User

Re: Update multiple SharePoint Items

@stgiesbrecht,

Are any of your columns in Approvers required?  Particularly look at the Title column, it is usually required by default in Sharepoint.

stgiesbrecht
Level: Powered On

Re: Update multiple SharePoint Items

The only required field I have in that list is "Title" which I have included in the Patch command.

Super User
Super User

Re: Update multiple SharePoint Items

Hi @stgiesbrecht,

 

If you are only adding new items form colApprovers to the Approvals dataset, the following code should work: 

  ForAll(colApprovers, Collect(Approvals, {ID: 1*Text(colID), Title: currentLoop & Text(colID)})

If you are editing exiting items, you will need the Patch code but I think I see the problem with your Patch code.  You have  extra curly braces. The syntax for Patch requires all fields being patched to be between the same curly braces and separated with commas. 

ForAll(colApprovers, Patch(Approvals,LookUp(Approvals, ID=Value(Text(colID))), {ID: Value(Text(colID))},{Title: currentLoop&Text(colID)})) should be 

ForAll(colApprovers, Patch(Approvals, LookUp(Approvals, ID=1*Text(colID)), {ID: 1*Text(colID), Title: currentLoop & Text(colID)}))

1*Text() is the same as Value(Text()) so I simplfied the formula to make it easier to read.

stgiesbrecht
Level: Powered On

Re: Update multiple SharePoint Items

@Drrickryp, first off thank-you for your help and suggestions.

 

I am updating existing and not adding new, so the Collect will not work in this case. I have updated the patch to remove the extra curly braces as follows:

ForAll(colApprovers,  Patch(Approvals, LookUp(Approvals,  ID=1*Text(colID)),  {ID: 1*Text(colID), Title: currentLoop & Text(colID)}))

Unfortunately it is still only updating the first item

 

Super User
Super User

Re: Update multiple SharePoint Items

I'm stumped.  Perhaps @v-monli-msft or @tchin-nin could take a look at it.

 
Super User
Super User

Re: Update multiple SharePoint Items

@stgiesbrecht

 

I'm not giving up.  I found an obscure reference for a similar problem that could perhaps help  Please try:

ForAll(colApprovers, Patch(Approvals, {ID: ID},  {ID: 1*Text(colID), Title: currentLoop & Text(colID)}))

I know it looks weird but it couldn't hurt to try it. If you get a value mismatch error just multiply one of the ID*1. 

One last thought.  What if you removed the {ID: and just patched the {Title: currentLoop & Text(colID)})

ForAll(colApprovers, Patch(Approvals, {ID: ID},  {Title: currentLoop & Text(colID)}))
stgiesbrecht
Level: Powered On

Re: Update multiple SharePoint Items

@Drrickryp, tried that and got the same results but also got an error message that "specified column is read-only and can't be modified"