cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Error Latch: UpdateContext({x: Patch(x,...)})

I've noticed an annoying trap in PowerApps recently. I have several elements on a page that update parts of a record in a context variable, using the form:

 

UpdateContext({ Record: Patch(Record, {field: changedvalue}) })

However, if I make a mistake in one of these, it forces Record to be of type Error. Unfortunately, even if I fix the issue, the line above in other parts of the page latches Record to be of type Error, as Patch(<Error>,...) returns a type <Error>.

 

The only way to clear this, I've found, is to comment out all of these UpdateContexts, and then uncomment them back into the project. 

 

I've found that even leaving the page and returning doesn't resolve the issue. Ideally, PowerApps could recalculate Errors in these recursive situations, or provide a a mechanism to allow you to reset the Error, and try again.

 

Is there any other methods of resolving this issue? 

2 REPLIES 2
Community Support
Community Support

Hi @bpm ,

 

I did a test on my side, and had the same issue with you.

Once the Record is locked to be Error type, it would not work any more even it is corrected, unless remove all related formulas.

Maybe you can try to use IfError function to avoid the mistakes, though I'm not sure if it is suitable for your scenario.

Overmore, you can submit an idea to PowerApps Ideas Forum to optimize recursive situations: https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

Best regards,

Sik

Thanks Sik, I did find another workaround using IsError. I replaced all the instances of:

UpdatedContext({x: Patch(x, ...) })

with

UpdateContext({x: Patch(If(IsError(x), Defaults('[dbo].[TableX]'), x), ...)})

and similarly, where I am attempting to get the new ID from a Patch to a table:

UpdateContext({x: Patch('[dbo].[TableX]', Defaults('[dbo].[TableX]'), If(IsError(x), {}, x), ...)})

This at least prevents the Error from propergating back to affect the type of X, and now can't latch the error.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (12,845)