Autosaving Data in Power Apps
Autosaving in Power Apps is a powerful feature that ensures user inputs are saved automatically without requiring explicit actions like clicking a “Submit” button. This is particularly useful for long forms, background data collection, draft saving, and real-time collaboration.
This guide will walk through every step in detail, covering methods for autosaving data, best practices, and performance optimization techniques.
1. Understanding Autosaving in Power Apps
1.1 What is Autosaving?
Autosaving means that user inputs are automatically saved to a data source (like SharePoint, SQL Server, Dataverse, or Excel) without manual submission.
1.2 Benefits of Autosaving
✅ Prevents data loss due to accidental exits or app crashes.
✅ Enhances user experience by eliminating the need for manual saving.
✅ Supports real-time collaboration (e.g., autosaving user progress).
✅ Speeds up workflows by reducing clicks and user actions.
2. Setting Up Autosaving in Power Apps
2.1 Data Sources Supported for Autosaving
Autosaving can be implemented with various Power Apps data sources, including:
- SharePoint Lists
- Dataverse Tables
- SQL Server Tables
- Excel Files (OneDrive/SharePoint)
- Collections (Temporary Data Storage)
3. Method 1: Autosaving Using the Timer Control
The Timer Control can periodically save form data to the data source without user intervention.
Step 1: Add a Form to Power Apps
- Go to → Insert → Forms → Edit Form.
- Set the DataSource property to your data source (e.g.,
OrdersList
). - Set the DefaultMode property to
FormMode.New
(for new entries) orFormMode.Edit
(for existing records).
Step 2: Add a Timer Control
- Go to → Insert → Input → Timer.
- Set these properties:
- Duration:
10000
(10,000 ms = 10 seconds, meaning the form saves every 10 seconds) - AutoStart:
true
(Timer starts when the form loads) - Repeat:
true
(Restarts after completion)
- Duration:
Step 3: Save Data When Timer Ends
Set the OnTimerEnd property to automatically save data:
If(EditForm1.Valid, SubmitForm(EditForm1))
- Ensures only valid data is saved.
- Automatically submits the form every 10 seconds.
Step 4: Hide the Timer Control
- Set the Visible property of the timer to
false
. - The autosaving will still work in the background.
4. Method 2: Autosaving When a User Changes Data (OnChange Event)
Instead of using a timer, you can save data as soon as a user modifies a field.
Step 1: Add Input Fields to Your Form
- Insert TextInput, Dropdown, or DatePicker controls.
- Link them to a data source.
Step 2: Add an Autosave Trigger (OnChange Property)
Set the OnChange property of each field:
Patch(OrdersList, ThisItem, {CustomerName: TextInput1.Text})
- This updates only the changed field in the database.
- No need for manual submission.
Example: Autosaving Multiple Fields
Patch(OrdersList, ThisItem,
{CustomerName: TextInput1.Text, OrderDate: DatePicker1.SelectedDate, OrderStatus: Dropdown1.Selected.Value}
)
- Saves CustomerName, OrderDate, and OrderStatus as soon as they are modified.
5. Method 3: Autosaving Drafts Using a Collection
If internet connectivity is unstable, store data locally in a collection before submitting it to the database.
Step 1: Store Data in a Collection
On the OnChange event of the input fields, store values in a collection:
Collect(AutoSaveCollection, {CustomerName: TextInput1.Text, OrderDate: DatePicker1.SelectedDate})
- This stores data locally without internet.
Step 2: Sync Data to SharePoint When Connected
Use a Timer Control or a Button Click to save data from the collection to SharePoint:
ForAll(AutoSaveCollection, Patch(OrdersList, Defaults(OrdersList), {CustomerName: CustomerName, OrderDate: OrderDate}))
Clear(AutoSaveCollection) // Clears local storage after syncing
- Ensures data is saved even if the user loses connection.
6. Method 4: Autosaving When Navigating Between Screens
If users navigate between screens before submitting data, save progress automatically.
Step 1: Add the Autosave Trigger to the Screen’s OnHidden Property
Set the OnHidden property of the form’s screen:
If(EditForm1.Valid, SubmitForm(EditForm1))
- Ensures the form is saved before the user leaves the screen.
Step 2: Save Changes When a User Clicks “Back”
Modify the OnSelect property of the “Back” button:
If(EditForm1.Valid, SubmitForm(EditForm1)); Navigate(HomeScreen, ScreenTransition.Fade)
- Saves changes before navigating back.
7. Best Practices for Implementing Autosaving
7.1 Prevent Overwriting User Inputs
If multiple users work on the same record, use a Timestamp Check to prevent overwrites:
Patch(OrdersList, ThisItem,
{LastModifiedBy: User().FullName, LastModifiedTime: Now()}
)
- Shows who made the last edit and when.
- Prevents overwriting by another user.
7.2 Optimize Performance
- Avoid frequent database updates. Instead, batch updates with
Concurrent()
. - Use collections for offline storage before submitting to the database.
- Limit the number of autosave triggers (e.g., save every 10 seconds instead of every second).
7.3 Show Confirmation to Users
Provide feedback to users when data is autosaved. Add a label that shows “Saved!” when data is successfully stored.
If(EditForm1.Valid, Notify("Data autosaved successfully!", NotificationType.Success))
8. Conclusion
Autosaving in Power Apps improves user experience and prevents data loss. By leveraging Timer Control, OnChange events, Collections, and AutoSave on Navigation, you can create a seamless and efficient autosaving mechanism.
Would you like a specific implementation for SharePoint, SQL Server, or Dataverse?