In the first part of this two-part blog series, I discussed an approach to use a Power App timer to perform AutoSave actions. While it works well, there are some caveats to consider around, such as frequency of saving and implications on data cross multiple screens. In this article, I am discussing a screen-specific approach for saving data automatically.
AutoSave using Power Apps, Part 1: Timers

In the case, where your app is made up of multiple forms, then the save functionality should be limited to only the form that the user is on.
OnVisible()
In Power Apps, screens are stacked on top of each other. All screens are refreshed while the app is running. There can only be one active screen at any time, which is the one shown and available for user interaction. When a user switches between screens, then to the app developer that is a trigger that, for the time being, the user completed working on the screen they are navigating away from.
The OnVisible() property for screens objects is used to execute expressions when the specific screen is moved to the top of the screens stack. This can be used to identify that the user is done with the previous screen. By capturing the name of the screen you navigating to in a varible, you can refer to it in the code from the previous screen to perform the save actions.
Set(lastScreen: App.ActiveScreen.Name)
Now, in order to perform the save actions, all you need to do is add the saving expressions before the set action to each screen. Since Power Apps requires controls to have unique names throughout, it’s not possible to simply refer to the screen name and control. Instead, you need to use an if-statement or switch-statement to perform the actions you want to perform
Switch(lastScreen,"Screen 1", <perform save tasks for screen 1>
"Screen 2", <perform save tasks for screen 2>
...
"Screen n", <perform save tasks for screen n>
);
Set(lastScreen: App.ActiveScreen.Name)
Centralizing Save Functionality
The OnVisible() approach discussed above works well for simple apps. However, in apps that include many screens with complex save functionality that overlaps, you may find yourself copying the code to each screen. This is tedious and could result in errors. To handle such scenarios, you should consider centralizing the save functionality. This can be achieved a Functional Programming approach in Power Apps that I discussed recently.
Conclusion
Overall, it’s possible to build AutoSave functionality into your Canvas Power Apps using various mechanisms. Before embarking on this journey, make sure you understand the ways in which the app will be used and measure them against any limitations, such as API limits, timing, performance, and data storage.
Originally published on Medium