The OnStart
property in PowerApps is super important to get right. Its the place to communicate critical info about your app to developers (and your future self) as well as setup users for a good experience. So how do you craft a great OnStart
config?
I'll break down each piece, then provide a complete example below.
As shown in the post Wheres the Code!?, the first place to find critical PowerApps code is the App OnStart
property. Place the most important comments about your app here. Author, change log, special logic, key functionality, etc. OnStart
provides a centralized place for simple documentation that travels with the app. Keep it short and concise. The curious can always reach out directly for more info.
Example:
/*==========================================
Copyright PowerApps.Rocks 2021
Author: Eric Thomas
Purpose: This app is used to capture cool data by ~40 people in the Greatness Dept.
Change log:
- v0.3
- Requestor: Sally Jones
- Notes: Added ability to capture photos
- v0.2
- Requestor: Bob Smith
- Notes: Fixed combobox issue; aligned header on screen 2
- v0.1
- Requestor: Bob Smith
- Notes: Bootstrapped new app; sent mvp to stakeholders for testing
==========================================/*
PowerApps has a built in User()
function that grabs some info about the logged in user without the need of additional API calls. Grabbing this info OnStart
allows you to personalize the app based on who is logged in. Its also a good time to define the user's organization or org unit if applicable.
Example:
Set(varUser, User()),
Set(varOrg, "PowerApps.Rocks")
varUser yields:
Use varUser.Email
value and the Office365Users
Connector to lookup more detailed user info later in app. Try to avoid using this OnStart
as it will delay loading a bit.
Example:
Set(varUserDetails, Office365Users.SearchUserV2({searchTerm:varUser.Email}).value)
There are a few simple values to define about the app itself that can be used on subsequent screens. App Name can be used on headers of each screen. Version Number and Environment can be used in footers on each screen to give users info on which app they are testing/using.
Example:
Set(varAppName, "Test App");
Set(varLogo, uploaded-media)
Set(varEnv, "DEV");
Set(varVersion, "v0.1");
Note: uploaded-media
refers to an embedded image added via File/Media
.
I like to provide users a "Bat Phone" to contact me (the developer) directly. I know its controversial to put users in direct contact with devs, but I've found this to have IMMENSE value:
Example:
Set(varSupportContact, "[email protected]");
Set(varSupportLink,
"<strong>
<a
style='color:blue'
href=mailto:" & varSupportContact &
"?subject=" & EncodeUrl("Support Request: " & varAppName) &
"&body=" &
EncodeUrl(
"Hello," &
Char(13) &
Char(13) &
"-Issue:" &
Char(13) &
Char(13) &
"Thank you," &
Char(13) &
varUser.FullName
) &
">Feedback Always Welcome
</a>
</strong>"
)
I tend to keep coloring very simple in the apps I build. I use a 3 color palette of Primary, Secondary and Accent Colors. Setting these in OnStart
allows me to call them easily throughout the app.
Example:
Set(varPrimaryColor, ColorValue("#27ad74")),
Set(varSecondaryColor, ColorValue("#00bfff")),
Set(varAccentColor, ColorValue("#f49d02"))
/*==========================================
Copyright PowerApps.Rocks 2021
Author: Eric Thomas
Purpose: This app is used to capture cool data by ~40 people in the Greatness Dept.
Change log:
- v0.3
- Requestor: Sally Jones
- Notes: Added ability to capture photos
- v0.2
- Requestor: Bob Smith
- Notes: Fixed combobox issue; aligned header on screen 2
- v0.1
- Requestor: Bob Smith
- Notes: Bootstrapped new app; sent mvp to stakeholders for testing
==========================================/*
Concurrent()
Set(varUser, User()),
Set(varOrg, "PowerApps.Rocks"),
Set(varAppName, "Test App"),
Set(varEnv, "DEV"),
Set(varVersion, "v0.1"),
Set(varLogo, pa_rocks_logo_p),
Set(varSupportContact, "[email protected]"),
Set(varPrimaryColor, ColorValue("#27ad74")),
Set(varSecondaryColor, ColorValue("#00bfff")),
Set(varAccentColor, ColorValue("#f49d02"))
);
Set(varSupportFooter,
"<center>" &
Char(169) &
varOrg &
Char(32) &
Year(Today()) &
Char(32) &
varVersion &
Char(32) &
varEnv &
Char(32) &
"<strong>
<a
style='color:blue'
href=mailto:" & varSupportContact &
"?subject=" & EncodeUrl("Support Request: " & varAppName) &
"&body=" &
EncodeUrl(
"Hello," &
Char(13) &
Char(13) &
"-Issue:" &
Char(13) &
Char(13) &
"Thank you," &
Char(13) &
varUser.FullName
) &
">Feedback Always Welcome
</a>
</strong>
</center>"
)
So why the heck would you do this?
Keep it simple!
Notice, there are no ClearCollect
statements, no Office365Users
API calls, etc. The best practice is to only perform API calls and such when the user needs to see the data. Don't make everyone wait while 1500 records are loaded OnStart
if only 10% of users actually need that data on screen 4 of the app! Use OnVisible
of screen 4 to make these calls instead.