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

Updating a variable after clicking the save button changes as expected but then changes back right away



I am currently building a simple form with a reminder pop up to select Save in the case a users tries to leave a page without saving. I am utilizing a variable varWarrantiesChanges that updates to true anytime a change is made without saving (OnChange property of my fields). If they don't make any changes in the form and navigate back, it goes back as expected as varWarrantiesChanges remains false. If they make a change without saving and hit back, varWarrantiesChanges is true and the popup comes up.


The issue I'm having is when they do select the save button, the following OnSelect() code is run:



UpdateContext({varWarrantiesChanges: false});


So the varWarrantiesChanges flag should be set back to false, and the popup should remain hidden when hitting the back button. When selecting save and running the OnSelect() code above however, varWarrantiesChanges updates to false for a split second and then updates right back to true for some reason. I assume it's something that SubmitForm() is doing, but I cannot figure out what it might be/what the fix is. Maybe SubmitForm() technically changes a field when submitting which triggers the OnChange? If anyone has a solution or a workaround for what I'm trying to do that would be much appreciated. 




Frequent Visitor

Solved my own problem - for those finding this and dealing with the same thing, use the Form property UnSaved to create form behavior. I did If(Form1.Unsaved, UpdateContext({varWarrantiesChanges: true}), Back()). This worked as expected.

Super User
Super User


Put the UpdateContext variable in the OnSuccess property of the form.   That way it will only change if the form is successfully saved. There is almost never a reason to chain commands after activating the SubmitForm(). You don't want a second function to execute if the form is not successfully saved.

If you are leaving that screen and coming back to it, use the Set() function to create a global variable as the UpdateContext() function resets if you leave the screen.

I actually did do that OnSuccess but the error remained. I used context variables on purpose as I have multiple forms that require the same behavior, I could try with global variables to see if that fixes it though. I was perplexed as to why it wouldn't work with the OnSuccess code....

Helpful resources

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.


New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,606)