In Power Apps, galleries are often connected to data sources such as SharePoint lists.
Understanding when and how to use the Refresh() function is essential for keeping your app data synchronized.
This article walks through different scenarios using an inventory management app connected to a SharePoint list of products.
Scenario 1: Manual Refresh with a Button
Suppose you have a gallery connected to a SharePoint list containing products like Notebook, Mouse, and TV.
You add a button labeled Refresh and set its OnSelect property to: Refresh(Products)
If you change data directly in SharePoint (e.g., update the TV price to 900) and then click the refresh button in Power Apps, the gallery updates with the new value.
This demonstrates that Refresh() pulls the latest data from the source.
Scenario 2: Using an Edit Form
When you add a record through an Edit Form in Power Apps, you typically use: SubmitForm(Form1)
After submission, the form resets and the gallery updates automatically without needing Refresh().
This is because the form submission directly writes to the data source and the gallery reflects the change immediately.
Scenario 3: Using Patch Function
Another way to add records is by using the Patch() function.
For example:
Patch(Products, Defaults(Products), {
Product: TextInputProduct.Text,
Price: Value(TextInputPrice.Text),
Quantity: Value(TextInputQuantity.Text)
})
This inserts a new record directly into the data source.
The gallery updates automatically, again without requiring Refresh().
When is Refresh Needed?
The Refresh() function is most useful when changes are made to the data source outside of the current user session.
For example, if another system or user updates the SharePoint list (e.g., reducing Notebook quantity from 20 to 10), your app will still display the old value until you call Refresh().
Best Practices
- Use
Refresh()when external changes occur outside of your app session. - For form submissions (
SubmitForm) andPatch()operations, refresh is not required. - Consider adding a Timer control to automatically refresh data every few minutes in scenarios where external updates are frequent.
Conclusion
In Power Apps, the Refresh() function ensures your gallery reflects the latest data from the source.
While not necessary for form submissions or patch operations, it becomes critical when external systems or users update the data.
By strategically using Refresh() or timers, you can keep your app data accurate and up to date.

Leave a Comment