Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Microsoft Power Apps

You're reading from   Learn Microsoft Power Apps The definitive handbook for building solutions with Power Apps to solve your business needs

Arrow left icon
Product type Paperback
Published in Sep 2023
Publisher Packt
ISBN-13 9781801070645
Length 702 pages
Edition 2nd Edition
Arrow right icon
Authors (2):
Arrow left icon
Elisa Bárcena Martín Elisa Bárcena Martín
Author Profile Icon Elisa Bárcena Martín
Elisa Bárcena Martín
Matthew Weston Matthew Weston
Author Profile Icon Matthew Weston
Matthew Weston
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Introducing Power Apps FREE CHAPTER 2. Creating Your First Canvas Power App 3. Creating Apps in SharePoint 4. Publishing and Leveraging in Power Apps 5. Exploring Controls 6. Exploring Formulas 7. Exploring Reusable Controls 8. Working with Data 9. Introducing Connectors 10. Using GPS in Power Apps 11. Working with Images and Barcodes 12. Securing Your Power Apps 13. Working Offline 14. Using Power Automate with Power Apps 15. Using Azure with Power Apps 16. Visualizing Data 17. Introducing Artificial Intelligence 18. Introducing Microsoft Dataverse 19. Introducing Model-Driven Apps 20. Creating Model-Driven Apps 21. Exploring Environments and Data Policies 22. Introducing the Future of Power Apps 23. Good Practices for Creating Power Apps 24. Other Books You May Enjoy
25. Index
Appendix

Returning data to Power Apps

When we think about functions and processes from a pro-code perspective, more often than not we pass data into a function to get something back. We can apply exactly the same thinking to our flows. As well as having a trigger to bring data in, we have an action that will allow us to return data from the flow to the app.

When we are looking for Power Apps actions, we need to follow the same process as we did for Outlook: search for the connector, and then select your action. So this time, when we search for our connector, we will search for PowerApps.

There are certain areas where the branding for Power Apps hasn’t been updated, and Power Automate is unfortunately one of them. So make sure you search for it without the space!

When we have located our connector, we can then select the Respond to a PowerApp or flow action:

Graphical user interface, text, application, email  Description automatically generated

Figure 14.17: Searching for a connecter to find actions

When we use this action, we can configure it in exactly the same way as we did with our trigger. Rather than defining inputs, instead we define outputs, by selecting + Add an output and selecting the type of data that we want to return.

When running the flow in test mode, the Respond to a PowerApp or flow action will always show as skipped. It will only fire when actually called from an app.

In our example, we will just return a simple response to the app to say that the email has been sent, returning a Boolean (yes/no) value. Rather than being asked to provide the description this time, as this is only available to the flow, we are asked to provide the value that we want to send back.

Just like with our email, we could use dynamic content to take the outputs of a previous action to send back to the app, or we could return the outputs of an expression. To keep it simple at the moment, let’s just return the value true.

To do this, we will use the dynamic content toolbox, but this time we will select the Expression tab and use the expression true to return the Boolean value to our app:

Graphical user interface, application  Description automatically generated

Figure 14.18: Responding to the Power App by returning a Boolean value

Now that we have looked at the ways in which we can build our flow, we need to look at how we can use this within our apps.

Calling a flow within Power Apps

Being able to use flows to handle all of our heavy processing is a great feature of the Power Platform. It means that we can keep our apps as light as possible, or reduce some of the more complex formulas to something that we can build visually.

In order to use our flow, we need to have an event that we can use to trigger the flow, such as the OnSelect event for a button, or the OnSuccess event for a form. To associate a flow and then use it, follow these steps:

  1. The first thing we need to do is decide where we want the flow to be executed. Do we want it to be executed from the screen or from a control? In this example, we’re going to execute the flow from a button, so we will place a button on the screen and ensure that it has been selected, as shown in the following screenshot:
Graphical user interface, application, Teams  Description automatically generated

Figure 14.19: Placement of a button that will execute the flow

  1. With the desired control selected, we need to navigate to the Power Automate button, on the left side of the screen. This will present a list of flows that are either already associated with the control or available for association. If you don’t see your flow listed, then you will need to make sure that your flow has been saved, and ensure that both the app and the flow are located in the same environment.

    Look for the flow that you want to use and take note of the flow name on the second row of text, as this is what you will need to know when calling it. In this example, it is PowerAppsTriggeredFlow:

    Figure 14.20: Flow name

  1. To associate the flow with the control, we simply need to click on the desired control and property that we are going to use to execute the flow, such as the OnSelect event. We can then start typing the flow name identified in the previous step into our formula:
Graphical user interface, application  Description automatically generated

Figure 14.21: Executing a flow using an event

  1. Selecting the .Run formula then allows us to provide any arguments to our flow to make it run. In this example, we want to provide the email address of the user who is logged in by using the User() formula. For this we would use the following formula:
    PowerAppsTriggerFlow.Run(User().Email)
    

Now, when the Run flow button is pressed, our app will pass the current user email value to execute the logic contained within the flow. Creating our formula in this way will allow us to push data to the flow, but not capture what is returned. In order to capture the returned data, we need to use a variable.

If we think back to earlier in the book, we created variables to temporarily store the data, and we can use the exact same formulas here. If we use a global variable, we would use the formula:

Set(gblFlowHasCompleted,PowerAppsTriggeredFlow.Run(User().Email))
Graphical user interface, text, application  Description automatically generated

Figure 14.22: Flow result from clicking the Run flow button in Power Apps

Once we have the output of the flow caught within a variable, we can then use that elsewhere in our app, e.g., we could then show a success message when the value is returned from the flow.

Now that we have covered the key components of creating flows, and how they interact with Power Apps, let’s now add this to a lab-based app.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image