Avoiding Parameter Chaos in PowerApps

Avoiding Parameter Chaos in PowerApps

I love PowerApps! This technology gives me the freedom to create a portable user interface (UI) for my demos in a couple of minutes. Well, sometimes it takes a little bit longer, especially when…

Direct before NAV TechDays 2019 I decided to create a PowerApp to demonstrate the power of our Intelligent ERP framework. To execute the needed API calls I attached a Power Automate flow to my PowerApp.

During setup of the flow I played a little bit to much with attaching parameters. Later in my PowerApp I realized, my flow had too many parameters and I had no clue where all these parameters came from.

Parameter Trouble

Let’s recap this in a small example. My PowerApp showed me a method signature like this:

OMG, what happened?

In my flow I added a parameter, afterwards I removed it and added the parameter again by using “Query in PowerApp”. As result I got parameter names like:
“Delay_Count”, “Delay_Count_1”, and “Delay_Count_2”.

Each of these parameters was added as required to Body of the PowerApps Trigger (Trigger-Menu: Peek Code):

My Question(s):
How can I prevent this behavior or is it possible to specify names for parameters?

Prerequisites: Creating a Flow as PowerApp Action

Let me demonstrate. To combine a PowerApp with Power Automate (aka Flow), goto Menu “Action”, “Power Automate” and use “Create a new flow”:

… or you can create a new flow direct in “Power Automate” by choosing a Template for PowerApps:

Another way is to build the flow from scratch. For this you must add a PowerApps Trigger to the empty flow.

Flow with named Parameters for PowerApps

My example flow does nothing special. It calls only a “Delay” action and the “Value” (delay in seconds) should be requested in my PowerApp. This is done by “Ask in PowerApps”:

This creates a new parameter named “Deley_Count”.

If you do this again and again you get parameters “Delay_Count_1”, “Delay_Count_2”, and so on… what I want to avoid!

The trick is to add for each needed parameters a Task “Initialize Variable” to my flow:

Set up the variable name as well as the name of the task (rename) to the expected name for the PowerApp e.g. “delaySeconds”:

Result should be:

Afterwards you can initialize the value of the task (Initialize Variable) “delaySeconds” as a requested parameter from PowerApp by using “Ask in PowerApps”:

When this is done, the PowerApp parameter is created.

Note: It is currently not possible to change the parameter name again.

My advise:
Do not set up any variables by “Ask in PowerApps” until you have completed your Flow and know which variable is needed.

Later you can use the initialized variable “delaySeconds” in your Flow as value for action “Delay” parameter “Count”:

Finally check and save the flow.

Conclusion

Good news, back in my PowerApp, the created flow requires now only the parameter “delaySeconds_Value”.

With this little trick it’s possible to define the requested variable names of a Power Automate flow. This give parameters a stronger meaning and improve the maintainability of a PowerApp.

Did you know this trick or do you have a better one? What is your preferred way to setup a Power Automate flow for PowerApps? I’m looking forward to read your comments.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *