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

Lab 12

Within this lab, we will use Power Automate to implement notifications when a new grocery is added using our app. First, we will create a flow that generates an email and sends it to the person who is going to receive the asset. Next, we will need to update the data source so that we can store the assignee and then generate the flow. Additionally, we will also use Power Automate to create a reminder flow for groceries that are close to their “use by” date.

To complete this lab, you will need to have a Power Automate license, which can be either a Microsoft 365/Dynamics 365 seeded license, a per-user plan, or a per-app plan.

Activity 1: Creating a flow for when a new grocery is added

  1. Navigate to the Power Automate portal and select Create from the left navigation.
  2. Select Instant cloud flow from the list of flows that we can create:
Graphical user interface, application, Word  Description automatically generated

Figure 14.23: Cloud flows available to select from the Power Automate portal

  1. When the Build an instant cloud flow window opens, press the Skip button:
Graphical user interface  Description automatically generated

Figure 14.24: Skipping the option to build an instant cloud flow

  1. When the flow canvas loads, select PowerApps from the list of connectors:
Graphical user interface, application  Description automatically generated

Figure 14.25: Filtering search results for triggers by selecting a connector

  1. When the list of triggers loads, choose PowerApps (V2) from the list of triggers:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.26: Selecting from the trigger list of the selected connector

  1. Press the + Add an input button on the trigger, and select Text as the data type, which we’re going to pass in.
  2. Name the Input as Email, and set the description text to Provide the email address for the notification.
  3. Repeat step 6, and add another text input called Item added:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.27: Adding a text input for the trigger

  1. Below the trigger, select + New step.
  2. Search the connectors for push notifications by typing Push into the search box.
  3. Select Send push notification V2 from the list of actions:
Graphical user interface, application  Description automatically generated

Figure 14.28: Selecting an action for the flow

  1. Configure the action in the following way:
    • Mobile app: Power Apps
    • Your app: Select the name of your app, i.e., Groceries Phone App
    • Recipients: Select the Email dynamic content from your trigger
    • Message: Use the Item added dynamic content from your trigger in the following message: A new <Item added> has been added to your groceries. Enjoy!
    • Open app: Yes
Graphical user interface, text, application, email  Description automatically generated

Figure 14.29: Configuring the action of the flow

  1. Click on the Untitled name in the top-left corner of your flow, and rename it to Send notification when grocery added.
  2. Finally, press Save.

Now that we have created our flow, we need to update our app so that we can use this to send a notification when we save a new grocery.

Activity 2: Adding the flow to the app

Let’s now go and open our app and start editing it. We are going to add the flow to run when our form has successfully been submitted:

  1. Open the Groceries Phone App that we’ve been working on throughout the labs.
  2. Click on the Grocery screen.
  3. Select the form frmGrocery_Grocery:
Graphical user interface, application  Description automatically generated

Figure 14.30: Opening the form from the Groceries phone app

  1. For this form, select the property selector next to the formula bar. You will see our formula in there, which handles the online or offline submission. We will add the ability to send a notification if we’re online, as we need to be online to reach the flow.
  2. With the OnSuccess formula still visible, start typing the name of the flow from Activity 1 without spaces: Sendnotificationwhengroceryadded and select the .Run function:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.32: Viewing arguments in the formula bar

  1. Our first argument was the email address, and the second was the grocery. So let’s update it based on the last-submitted record. Update your flow to look like this:
    Sendnotificationwhengroceryadded.Run(User().Email, frmGrocery_Grocery.LastSubmit.Title)
    
  2. Now, let’s bring our old formula back from Notepad. Our flow run formula needs to be directly below the Patch formula:
Graphical user interface, text, application  Description automatically generated

Figure 14.33: Typing the flow run formula below the Patch formula

  1. Finally, save, publish, and test your app and flow combination and observe the outcomes.

Activity 3: Creating a reminder flow

One of the key pieces of information that we gather within our app is the “use by” date, so we have a good opportunity to create a really useful flow that will check to see how many of our groceries need to be used within the next seven days. This will help us prioritize using those rather than longer-life goods:

  1. Navigate to the Power Automate portal (make.powerautomate.com) and select + Create from the left navigation.
  2. Once again, we will start our flow from blank. This time, however, we will select a Scheduled cloud flow:
Graphical user interface, application  Description automatically generated

Figure 14.34: Option to create a scheduled cloud flow from the Power Automate portal

  1. When the Build a scheduled flow window appears, enter the following configuration:
    1. Flow name: Use by date reminders
    2. Starting: Select tomorrow’s date, at 6 AM
    3. Repeat every: 1 Day

    Your screen should then resemble the following screenshot:

    Graphical user interface, application  Description automatically generated

    Figure 14.35: Setting the flow name and run recurrence

    Once completed, press Create.

  1. Once our Power Automate canvas appears, notice that we have our recurrence trigger already created for us. Click + New step below our trigger to add our first action.
  2. The first action that we’re going to use is a simple Compose action to allow us to calculate the date in 7 days’ time. The reason why we’re using Compose is so that we can see it building up step by step.

    Use the search box in the Choose an operation selector to search for the Compose action and click it so that it is added to the canvas.

  1. We are going to use an expression within this Compose action to calculate our date. Click into the Inputs text box and then select Expression from the toolbox that has opened to the right-hand side:
Graphical user interface, application  Description automatically generated

Figure 14.36: Opening the formula bar to enter an expression into the Compose action

  1. Enter the following expression:
    addDays(utcNow(),7,'yyyy-MM-dd')
    

    Then press OK:

    Graphical user interface, application  Description automatically generated

    Figure 14.37: Formula bar with the entered expression

  1. We now need to tell our flow to retrieve data from SharePoint so that we can find the info we need. Click the + New step button below our Compose action.
  2. When the Choose an operation box is displayed, we will first find our SharePoint connector, so that we can reduce the overall number of actions to just those we potentially want to use.

    Once you see SharePoint in your list, click the SharePoint icon:

    Graphical user interface, application  Description automatically generated

    Figure 14.38: Finding the SharePoint connector in the Choose an operation box

  1. Once we have our connector selected, choose the Get items action. You can reduce the overall list of actions by filtering for the word Item:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.39: Finding the Get items action within the SharePoint connector

  1. Once the Get items action has been added to the canvas, we can then configure it. Select the SharePoint site where you have created your list, and select the list that contains your list of groceries:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.40: Entering a site address and list name into the Get items action

  1. We have now told the flow to get a list of items, but currently, this will return everything from the list. We only want it to give us a list of items that are due to expire next week. For this, we need to add a filter query to our action, which we can see when we click on Show advanced options in the bottom left of the action.
  2. When we write a filter query, we need to write them in a very specific way; otherwise, an error will occur. We need to write it as the ColumnName (with no spaces), then an operator such as equal to, and then finally what we want to compare it to. For this activity, we will build the query so that it will filter for any items where the use by date is less than or equal to today’s date + 7.

    The skeleton of our filter query will therefore be:

    UseByDate le ''
    

    Note this uses two single quotes. This should resemble the following screenshot:

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

    Figure 14.41: Adding a filter query to the Get items action

  1. Place your cursor between the two single quotes of the filter query '' and then select the outputs from your Compose action from the dynamic content selector:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.42: Adding the output of the Compose action to the filter query

  1. Now that we have a list of items being returned from SharePoint, we need to take the data and add it to an email so that we can be notified of what needs to be used as a priority.

    But first, we need to format the outputs into something that can be used. For that, we’re going to use a simple HTML table.

    Click + New step, locate the Create HTML table action, and place it onto your canvas.

  1. Once the Create HTML table action is on your canvas, place your cursor in the From text box, and select value from the dynamic content selector:
Graphical user interface, application  Description automatically generated

Figure 14.43: Building the Create HTML table action

  1. Click on Show advanced options, where you will see an option for Columns. The default is set to Automatic, so be sure to change this setting to Custom:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.44: Adding a columns option to the Create HTML table action

  1. We can now add our own headers and values. We will type into the Header column, and add dynamic content into the Value column. Use the following pairs:
    1. Header: Item, Value: Title
    2. Header: Type, Value: Grocery Type Value
    3. Header: Use by date, Value: Use By Date
Table  Description automatically generated

Figure 14.45: Creating heads and values for the HTML table

  1. Now that we have our items being formatted into a basic table, we can add this to an email that can be sent to us each day. Click + New step and add the Send an email (V2) action:
Graphical user interface, text, application, email  Description automatically generated

Figure 14.46: Adding a Send an email (V2) action to the flow

  1. Configure the action to use your chosen email address, and set the Subject to Daily grocery report.
  2. In the Body text box, type in the following text, including the colon:The following grocery items need to be used within the next seven days:.
  3. Below the text we’ve just typed, from the dynamic content selector, select Output from the Create HTML table action.

Now, when our flow runs, we will be emailed with a basic list of items that are due to expire soon. You can test this by clicking on Test in the top-right corner of the screen, and then selecting Manual test. Follow the on-screen instructions and run the flow.

Congratulations! You’ve now created a daily reminder by using a scheduled cloud flow, as well as creating a flow notifying you when new items are added by using an instant cloud flow, which we added to the app itself.

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