Saturday, May 9, 2020

On-Demand Microsoft Flow for Dynamics 365 and PowerApps

On-Demand Microsoft Flow - What is it?

If you have been using Dynamics 365 (CRM) for sometime, you will know about on-demand workflows. They are a way to allow users to run automation only when needed. They will not run through some sort of automated trigger.
So, like the on-demand workflows of old, we are now in the age of Microsoft Flow. We can now create on-demand Microsoft Flows to provide on-demand automation.

First Things First - Dynamics 365 Settings

Prior to utilizing Microsoft Flows within Dynamics 365, you will need to enable this setting. New versions of Dynamics 365 since the October 2019 update will have Microsoft Flows already enabled.
To enable the setting, you will need to navigate to Settings>System Settings>Customizations. Next, click on "Yes" under "Enable Microsoft Flow".
Microsoft Flow setting in Dynamics 365

Second Things Second(?) - PowerApps Settings

The Power Platform Admin Center contains the Microsoft Flow setting as well. To enable the setting, you will need to navigate to https://admin.powerplatform.com>Click your Environment name>Settings>Behavior. Next, toggle the "Show Microsoft Flow on forms and in the site map" setting to "On".
Microsoft Flow setting in Power Platform admin center

Microsoft Flow Menu Button

Once the settings are enabled, the Microsoft Flow menu button will be visible in various places. First, you will see the menu button above a view in Dynamics 365.
Microsoft Flow menu button above a View
Second, you will see the menu button at the top of a record form in Dynamics 365.
Microsoft Flow menu button on a record form
Third, you will see the Microsoft Flow option in the classic Dynamics 365 Settings Menu.
Microsoft Flow option in the Dynamics 365 Settings
Fourth, you will see the menu button at the top of a view in a model-driven PowerApp.
Microsoft Flow menu button above a View in PowerApps
Fifth, you will see the menu button at the top of a record in a model-driven PowerApp.
Microsoft Flow menu button on a record form in PowerApps

Start Creating the On-Demand Microsoft Flow

Now, we are at the fun part of creating a Microsoft Flow! You can start your Microsoft Flow creation in a couple of ways. You can navigate to https://flow.microsoft.com, or you can navigate to https://make.powerapps.com and select "Flows" on the right-hand side.
The example today will be a simple one, and it's only meant to demonstrate how to set up the on-demand Microsoft Flow.
On the Microsoft Flow site, click on "New" and select "Instant - from blank".
Microsoft Flow create new Instant Flow
Next comes a small tip you need to know. When the "Build an instant flow" window appears, the "When a record is selected" option is NOT visible.
Build an instant flow - When a record is selected is missing
Now, click on the "Skip" button at the bottom, and this will load the "Search connectors and triggers" screen.
Microsoft Flow - Search connectors and triggers screen
Now comes the tip. Type "Common Data Service" in the search field, and you will now see the "When a record is selected" option.
Build an instant flow - When a record is selected is now visible

Building the On-Demand Microsoft Flow

After the "When a record is selected" option is available, select it. Next, give your Microsoft Flow a name, and then select an Environment and an Entity. Also, be sure to rename the first step to something more meaningful.
Build an instant flow - Creating a Flow - First Steps
The next step will update the Account Name on the Account record to uppercase.
Build an instant flow - Creating a Flow - Next Step
  1. Rename the step
    • Always put a meaningful name on your Flow steps.
  2. Select the Environment
    • Use the "Current" option from the list. This will make exporting and importing Flows from environment to environment easier.
  3. Select the Entity
    • Choose the correct entity to use in the action.
  4. Input the "Record Identifier"
    • Select the "Account" option using the fields available from the prior step.
  5. Update the field
    • This is where the Account Name will get updated to uppercase. The formula to use here is toUpper(triggerBody()?['entity']?['name']).

Microsoft Flow Tips

Before we continue, I wanted to provide some quick tips to help you build the expression used above. The expression portion of "triggerBody()?['entity']?['name']" is the code for the Account Name field. Now, let's look into how you can obtain this.
First, let's get the code for the Account Name field. Select the "Account Name" field from the list so that it appears in the field. Then click on the ellipsis button and choose "Peek code".
Build an instant flow - Expression tips
Second, look in the code list and you will see the "name" code in the middle. Highlight the code to copy it, but DO NOT copy the "@" symbol and the "" quotes.
Build an instant flow - Peek code info
Third, you need to know how to input an Expression. Remove the "Account Name" field you just added, and click on the field in the action step. Next, choose the Expression tab on the pop-out box.
Build an instant flow - Start the input of an Expression
Fourth, type in the expression "toupper()" (without quotes) in the Expression field. Now, paste the code you copied from the second step above. The expression should look like the below screen shot.
Build an instant flow - Expression code
Lastly, your Flow should look like this. Be sure to save the Flow now.
Build an instant flow - Finished Flow

Running the On-Demand Microsoft Flow in Dynamics 365

The last step is to run the Flow in Dynamics 365, and in PowerApps, to see if it will work. After you have saved your Microsoft Flow, you should now see it within the Microsoft Flow menu button.
Microsoft Flow menu button
Next, click on the Flow and a "Run Flow" window will pop up. Click on the "Run Flow" button.
Microsoft Flow menu button - Run Flow
Once the Flow runs, you should refresh the list and you will see the "Consolidated Messenger" account name is now uppercase.
Microsoft Flow - Account Name is now uppercase

Running the On-Demand Microsoft Flow in PowerApps

Lastly, let's look at this within a model-driven PowerApp.
Microsoft Flow menu button in model-driven PowerApp
After the Flow has been run, you will now see the Account Name is uppercase.
Microsoft Flow - Account Name is now uppercase in model-driven PowerApp

In Closing

You will need to keep in mind that the Flows need to be set up for each Environment. I had set up 2 Flows with one for the Dynamics 365 environment and one for the PowerApps environment.

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...