Skip to main content

ConfirmExit for canvas apps

Headshot of article author Greg Lindhorst

Nobody wants to lose unsaved changed.  And yet there are many ways to exit a canvas app while still in a dirty state, from closing the browser tab to swiping back to the list of apps on the phone.

Now there is a way to prevent losing unsaved changes.  The App object has two new properties:

  • ConfirmExit:  A Boolean that when true will show a confirmation dialog before exiting the app, preventing the accidental loss of data.
  • ConfirmExitMessage: A custom text message to display in the confirmation dialog.  A generic message is provided by default.  Use this to direct your users to the data that hasn’t been saved yet.

For more details, we’ve expanded the App object documentation.

For example, here I have a simple gallery and form over the CDS Contacts entity.  The formula App.ConfirmExit = Form1.Unsaved is shown.

If we run this app in a browser and change one of the fields, the browser won’t allow us to close the app without first confirming.  Three different ways are shown for closing the app: using the Exit function, closing the browser tab, and closing the entire browser.  After saving the change to the record, the form control will no longer be in an unsaved state, and then any of these gestures will close the app.

We have a similar experience on iOS and Android.  If you use the Exit function or swipe from the left to bring up the list of apps (to change apps):

There is a small caveat.  These properties can reference any variables or controls in your app.  But at present, these properties can only reference controls on the first screen if the Delayed load preview feature is enabled (which it is by default for new apps). If offending references are made, PowerApps Studio doesn’t show an error, but the resulting published app doesn’t open in PowerApps Mobile or a browser. We’re actively working to lift this limitation. In the meantime, you can turn off Delayed load in File > App settingsAdvanced settings (under Preview features).

You will also need a newer version of the iOS and Android players for this feature, version 3.19041 or later.  That has been out for some time and most users should have already upgraded.