
Power Apps is an declarative low code solution that has often been compared to Excel in that modifying a value somewhere in an app will update all its references throughout. This is all great, but in some cases it would be great to execute entire blocks of code to complete more complex tasks.
Suppose we have a scenario, where the app needs to perform calculations on some numbers and then modify a SharePoint item. There are three buttons available, where each button will update the item using different values.
One option is to have is to write the calculations and Patch() functions for the first button and then copy them to the other button’s OnSelect() property and make the necessary modifications. Possible, but not ideal. What if the logic has to change a bit? You will need to update the code for all three buttons. Now imagine there are fifty buttons that perform almost the same tasks. You can see where I’m going with this…
The Timer Cheat
To overcome this hurdle, I use something I call the Timer Cheat. Essentially, I’m using a timer to perform the repetitive actions. In a nutshell, I take the following approach:
- For each repetitive action, create a timer
- Define a parameter that will be used to start the timer (e.g. t1Start)
- Set the timer’s Duration parameter to 0
- In the timer’s OnTimerStart() property, add all the functions you want to perform
- In the timer’s OnTimerEnd() property, set the timer start parameter to false
Now all you need to do to call the code that is executed by the timer is set the timer start parameter (e.g. t1Start) to true. If there are any variables that you want to use inside the timer’s code, make sure to set them before you set the start parameter to true.
Simple solution to a frustrating problem. Happy (low-code) coding!
Originally published on Medium