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
News & Announcements

Community Blog

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

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (9,453)