Learn how to use the On Start property in Power Apps to initialize your app with global variables, collections, and user-specific settings.
What Is the On Start
Property?
The On Start
property is part of the Power Apps App object and is used to execute code when the app launches.
It’s ideal for initializing global variables, loading data, setting up collections, and other setup logic that should run before any screen is displayed.
Where to Find the OnStart
Property
- Go to the Tree View in Power Apps Studio.
- Select App under the “Screens” section.
- In the properties dropdown, select On Start.
You’re now ready to add your initialization formulas to the app’s OnStart
event.
Why Use On Start
?
- It runs once when the app is opened by the user.
- It’s the best place for initializing global state.
- Improves performance by caching frequently used data in variables or collections.
Common Use Cases and Examples
1. Set a Logo URL
Set(logoURL, "https://example.com/logo.png")
Use this variable in image controls across multiple screens:
Image = logoURL
2. Get the Current Logged-in User
Set(currentUser, User())
Example usage:
"Name: " & currentUser.FullName
3. Store User Email in a Global Variable
Set(currentUserEmail, currentUser.Email)
4. Load User Preferences from SharePoint
Assuming you have a SharePoint list named UserPreferences:
ClearCollect(
userPreferenceCollection,
Filter(UserPreferences, userEmail = currentUserEmail)
);
If(
CountRows(userPreferenceCollection) > 0,
Set(preferredTheme, First(userPreferenceCollection).theme);
Set(preferredView, First(userPreferenceCollection).view)
)
This allows you to use preferredTheme
and preferredView
throughout your app.
5. Detect User Language
Set(userLanguage, Language())
Displays something like: "en-US"
for English users.
6. Check if the User Is an Admin
Assuming you have a SharePoint list called AdminsList:
Set(
isAdmin,
!IsBlank(
LookUp(AdminsList, userEmail = currentUserEmail)
)
)
This sets isAdmin
to true
or false
depending on whether the user exists in the admin list.
How to Test the On Start
Property
While developing, the On Start
code doesn’t run automatically. To manually trigger it:
- Go to the App object in the tree view.
- Click the three dots (context menu).
- Select Run On Start.
Best Practices
- Use
Set()
to create global variables available throughout the app. - Use
ClearCollect()
to load reusable collections. - Keep
OnStart
lightweight — avoid slow operations that delay app startup. - Use conditional logic (e.g.,
If()
) to control what gets initialized based on the user or environment.
Summary
The On Start
property in Power Apps is a powerful tool to initialize global variables, retrieve user data, load collections from SharePoint or other data sources, and set up the app environment. When used effectively, it improves performance and simplifies app logic by centralizing common data access and configuration at startup.
Leave a Comment