cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate II
Advocate II

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
Highlighted
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
Highlighted
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

Highlighted
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.

Highlighted
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.
Highlighted
Community Support
Community Support

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.
Highlighted
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.
Highlighted
Helper I
Helper I

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
Ignite

Microsoft Ignite

This will be a conference that you do not want to miss!

secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,843)