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
v-siky-msft
Level 8

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
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 193 members 5,126 guests
Please welcome our newest community members: