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
- Navigate to the Power Automate portal and select Create from the left navigation.
- Select Instant cloud flow from the list of flows that we can create:
Figure 14.23: Cloud flows available to select from the Power Automate portal
- When the Build an instant cloud flow window opens, press the Skip button:
Figure 14.24: Skipping the option to build an instant cloud flow
- When the flow canvas loads, select PowerApps from the list of connectors:
Figure 14.25: Filtering search results for triggers by selecting a connector
- When the list of triggers loads, choose PowerApps (V2) from the list of triggers:
Figure 14.26: Selecting from the trigger list of the selected connector
- Press the + Add an input button on the trigger, and select Text as the data type, which we’re going to pass in.
- Name the Input as
Email
, and set the description text toProvide the email address for the notification
. - Repeat step 6, and add another text input called
Item added
:
Figure 14.27: Adding a text input for the trigger
- Below the trigger, select + New step.
- Search the connectors for push notifications by typing
Push
into the search box. - Select Send push notification V2 from the list of actions:
Figure 14.28: Selecting an action for the flow
- 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
- Mobile app:
Figure 14.29: Configuring the action of the flow
- Click on the Untitled name in the top-left corner of your flow, and rename it to
Send notification when grocery added
. - 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:
- Open the Groceries Phone App that we’ve been working on throughout the labs.
- Click on the Grocery screen.
- Select the form frmGrocery_Grocery:
Figure 14.30: Opening the form from the Groceries phone app
- 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.
- With the OnSuccess formula still visible, start typing the name of the flow from Activity 1 without spaces:
Sendnotificationwhengroceryadded
and select the.Run
function:
Figure 14.32: Viewing arguments in the formula bar
- 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)
- Now, let’s bring our old formula back from Notepad. Our flow run formula needs to be directly below the
Patch
formula:
Figure 14.33: Typing the flow run formula below the Patch formula
- 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:
- Navigate to the Power Automate portal (make.powerautomate.com) and select + Create from the left navigation.
- Once again, we will start our flow from blank. This time, however, we will select a Scheduled cloud flow:
Figure 14.34: Option to create a scheduled cloud flow from the Power Automate portal
- When the Build a scheduled flow window appears, enter the following configuration:
- Flow name:
Use by date reminders
- Starting: Select tomorrow’s date, at 6 AM
- Repeat every:
1
Day
Your screen should then resemble the following screenshot:
Figure 14.35: Setting the flow name and run recurrence
Once completed, press Create.
- Flow name:
- 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.
- 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.
- 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:
Figure 14.36: Opening the formula bar to enter an expression into the Compose action
- Enter the following expression:
addDays(utcNow(),7,'yyyy-MM-dd')
Then press OK:
Figure 14.37: Formula bar with the entered expression
- 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.
- 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:
Figure 14.38: Finding the SharePoint connector in the Choose an operation box
- 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
:
Figure 14.39: Finding the Get items action within the SharePoint connector
- 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:
Figure 14.40: Entering a site address and list name into the Get items action
- 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.
- 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:
Figure 14.41: Adding a filter query to the Get items action
- 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:
Figure 14.42: Adding the output of the Compose action to the filter query
- 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.
- 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:
Figure 14.43: Building the Create HTML table action
- 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:
Figure 14.44: Adding a columns option to the Create HTML table action
- 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:
- Header:
Item
, Value:Title
- Header:
Type
, Value:Grocery Type Value
- Header:
Use by date
, Value:Use By Date
- Header:
Figure 14.45: Creating heads and values for the HTML table
- 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:
Figure 14.46: Adding a Send an email (V2) action to the flow
- Configure the action to use your chosen email address, and set the Subject to
Daily grocery report
. - 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:
. - 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.