If you're looking to enhance the functionality of your Power App, consider using Power Automate to create flows.
Using a Flow can be a great way to enhance the functionality of your Power App. There are a number of common patterns that app developers implement that simply don’t have straightforward methods for dealing with PowerApps. Consider things like iterating through a data set and taking action on each row, manipulating and saving files among some of these things. In fact, many of the great no-code/low-code workarounds and tutorials on the internet involve using Power Automate to make these things happen. In that way, Power Automate flows can be a missing piece of the app puzzle.
Let’s jump right in and work through connecting a simple Canvas App to some Power Automate flows.
First, we’ll add a new screen to our application and call it `AutomateScreen`.
From the Insert menu add a button and set the text to `Start Flow`.
In the OnSelect property of the button, we’re going to connect to our first Power Automate flow. With the button selected, click the `Action` menu.
Next, click the `Power Automate` option in the Action menu.
You’ll then be prompted to create a new Data connection. Click the `+` to create a new flow.
This will take you to a new browser tab with a host of flow templates that start from a Power Apps button. You can choose any one of these, or you can simply create a blank flow by choosing the `Create option` on the left menu.
Next, click `Instant cloud flow`, specify a Flow name and select `PowerApps` as the trigger for this flow, and click `Create`.
Now we have our button-triggered flow. Let’s do something simple and test it out. In this case, I’m going to Create an approval.
Now, save the flow and flip back to the Power Apps studio. You should see a new flow available in the Data connection prompt. In this case, I’ve named it Start Flow Button.
Select this new flow and it will add a data connection in your application and it will add a partial expression to the OnSelect property of our button.
Let’s finish the expression in the OnSelect as follows.
Now, play the application and test the new button. Did you get an approval request?
Now, what if we want to add a little intelligence to this connection. Maybe we need to send some information into the flow to make it more useful. When building the flow, you may have noticed an option to Ask in PowerApps.
This is a very easy way to define any parameters that you want to pass into the flow from your Power App. Now, back in our flow, let’s make some adjustments. Instead of hard coding our Approval Title to `Test Approval` let’s Ask in PowerApps. Select the `Title` field and empty it, then click `Ask in PowerApps` from the Dynamic content.
This will automatically insert a PowerApps parameter that comes from the TriggerBody content.
Now, save the flow and flip back to PowerApps Studio. If you have to, play the app and click the `Start Flow` button to force Power Apps to refresh the connection. At this point, you should have an error on the OnSelect property of the button. The easiest way to resolve this is to remove the Start Flow Button data connection from the Data tab and then reconnect it by selecting the `Start Flow` Button flow again for the OnSelect property of the button.
This time, when it’s added, the IntelliSense in the expression editor will tell us we need to specify the title parameter.
Next, let’s add a simple text input to capture the title so that we can send this into the flow.
Now, in the OnSelect of the button, call the flow while passing in our new title value.
Next, play and test the application. Enter a title and click the `Start Flow` button.
The title or subject of the approval notification should have your title.
Ok, so the takeaway or tip from this first section is to remember that option in your flow to Ask in PowerApps. You can use this option throughout your flow to add parameters to your flow that are passed in from your Power App.