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

Verify ForAll/Patch in Form OnSuccess

Within OnSuccess for a form that submits to a SharePoint list I have a ForAll loop that patches a separate related SharePoint list with multiple records.

 

Patching this related SharePoint list works in most instances, but occasionally fails. I can't use the method of using UpdateContext to retrieve the records updated by the patches because you can't use an UpdateContext within a ForAll.

 

How can I catch this error and retry the patch?

 

Refresh('My SharePoint List');
ForAll( MyCollection, Patch( 'My SharePoint List', Defaults('My SharePoint List'), { ChoiceField1: { '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", Id: ChoiceValueID, Value: ChoiceValue }, Amount: Value(Amount), Record_ID: CreateItemForm.LastSubmit.ID } ) );

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Verify ForAll/Patch in Form OnSuccess

@gmcanally 

You could use the Errors function after the ForAll to check the status of any records in error. If there are any records returned from the Errors('My SharePoint List') function, you can act on them accordingly. 

What kind of failures are you seeing from that and how would you expect to recover from them?  I would address that first to determine the best way to lay this out. 

 

I hope that gives you some ideas.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Verify ForAll/Patch in Form OnSuccess

@gmcanally 

You could use the Errors function after the ForAll to check the status of any records in error. If there are any records returned from the Errors('My SharePoint List') function, you can act on them accordingly. 

What kind of failures are you seeing from that and how would you expect to recover from them?  I would address that first to determine the best way to lay this out. 

 

I hope that gives you some ideas.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Super User
Super User

Re: Verify ForAll/Patch in Form OnSuccess

Hi @gmcanally 

On the subject of not being able to use UpdateContext within ForAll, it might be useful to know that you can call the Collect function within ForAll in order to save your Patch results into a local collection. In addition to @RandyHayes's good advice, this might help you further diagnose your problem.

Super User
Super User

Re: Verify ForAll/Patch in Form OnSuccess

@timl good call...that was my next point to make, but didn't want to "complexify" too much until the real purpose was determined 😉  But yes, this concept of collecting as you go through the ForAll is helpful and more, especially with an Offline or spotty connected app.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Community Support Team
Community Support Team

Re: Verify ForAll/Patch in Form OnSuccess

Hi @gmcanally ,

Do you want to update multiple records at once?

In addition to use collection, you could also try to use Addcolumns/Renamecolumns,

Here's a doc for your reference:

https://powerapps.microsoft.com/ru-ru/blog/bulk-update-using-forall-and-patch/

 

 

Best regards,

Community Support Team _ Phoebe Liu

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: Verify ForAll/Patch in Form OnSuccess

@gmcanally 

Did any of the suggestions help you with your issue, or are you still having problems with it?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Cripp88
Level: Powered On

Re: Verify ForAll/Patch in Form OnSuccess

I'm currently having an issue where ForAll/Patch isn't working when invocated within the OnSuccess event of a form.

 

If I copy the ForAll & Patch to a button and click it the records are added to the data source perfectly.

 

Patching without ForAll works within the same code block in OnSuccess so I know the event is firing correctly. It seems there may be an issue using this combination of functions within OnSuccess.

 

This is annoying as you can get clashes when Patching from a submit button, so the best practice is to do Patching after the form has submitted. You also need to use OnSuccess if you need LastSubmit.ID for your patches.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,528)