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

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
Microsoft v-siky-msft
Microsoft

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

bpm
Level: Powered On

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
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (5,248)