For the uninitiated, locating the critical code within a PowerApp can be quite a source of frustration. Involving things like inheriting the code of others and non-standard code placement and even seasoned PowerVets reel at the thought of a full reverse-engineer in order to find everything.
In this post I'll give you the roadmap I wish I had when starting out. You'll be able to follow the steps below to locate all the critical code within a PowerApp.
PowerFX functions (code) can be written on most control properties. (See Must-know PowerApps Definitions for help with these terms.). Developers, rookie and veteran alike, have free reign to choose the location of their code.
Examples:
OnSelect
property of a button controlOnChange
property of a combobox controlAs such, the more controls an app has, the more potential places there are for code to be written (and hidden!). There isn't a great way to "show me all the codez" in PowerApps, so you need a mental model of the way code should be laid out as a baseline.
OnStart
of the App control is always the first stop in determining how a Powerapp works.
You should find some nice config code here. Not finding code here gives you some clues. It likely means the app is either very simple or perhaps made by someone new to PowerApps.
OnVisible
of the first screen of the app is the next logical point of code execution in a PowerApp.
Sometimes, the config code is located here instead of OnStart
.
If there are any call-to-action buttons or icons on the first screen, you'll likely find code placed on their OnSelect
properties.
If you find functions like ClearCollect()
here, the app was likely built a long time ago and hasn't been refactored for performance yet or was made by someone new to PowerApps. A best practice is to only GET data when loading the screen where data will actually be used.
The call-to-action buttons/icons will likely take users to a different screen within the app. The OnVisible
property of subsequent screens is the next likely location for code.
This is also a good place to put any ClearCollect()
functions that will GET data to display to users on this screen. Stick with this just-in-time mindset for getting data and your users will be happy!
Nearing the end of our tour here, the next place to check for code is on the controls within each screen. Specifically the actionable properties such as:
OnSelect
(anything; images, buttons, icons, dropdowns, labels, etc.)OnChange
(dropdowns, comboboxes, etc.)OnCheck
/ OnUncheck
(checkboxes)OnAddFile
/ OnRemoveFile
/ OnUndoRemoveFile
(Attachments control)Inspect the properties of any control a user interacts with.
This is the last formal stop on the tour, but can sometimes hold the most complex code within a PowerApp.
Forms have some critical properties where code can be "hiding".
Forms:
Item
property
DataSource
OnSuccess
/ OnFailure
/ OnReset
(little devils!)Default
of each field within a formUpdate
of each data card in a formGalleries:
Items
property of gallery controls (FOCUS HERE!)
Filter()
logic in the entire appPowerApps developers like to move things around the screen, shrink, animate, show, hide etc. These actions often involve the various display properties of a control.
These can get complex!
DisplayMode
of each control in the app
Height
/ Width
/ Visible
and all other display properties of each control in the app
A few oddballs that might present themselves...
DefaultSelected
and DefaultSelectedItems
of each combobox
HTMLText
of all HTML Text controls
A standard approach and placement of code goes a long way in maintainability.
Follow this little map to find code in PowerApps
OnStart
OnVisible
of first screenOnSelect
of any call-to-action buttons/icons on first screenOnVisible
of subsequent screensOnSelect
, OnCheck
, OnChange
, etc.Item
, Items
, OnSuccess
, etc.Height
/ Width
/ Visible
, etc.DefaultSelectedItem
, HTMLText
, etc.Happyapping!