cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Community Support
Community Support

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

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

Highlighted
Frequent Visitor

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

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
secondImage

New Return to Workplace

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

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 (6,748)