Automatically updating the stage of a Business Process Flow using Power Automate Flow

Glendon Thaiw
14 min readAug 14, 2021

--

So, I’ve been learning more about the Microsoft Power Platform and its integration with Dynamics 365 over the past couple of weeks. Part of my growing intrigue falls within the Business Process Flow (BPF) and how easily it is to tailor a BPF to suit different business cases (e.g. software development lifecycle, sales pipeline, etc). This guide aims to demonstrate the flexibility of managing BPFs programmatically in order to improve its extensibility to facilitate intricate and complex workflows.

TLDR: The stages of a Business Process Flow can be adjusted by the admin/agent through the Customer Service Hub graphical interface. This guide establishes a mechanism to alter the status of a BPF programmatically using a Power Automate Flow.

What’s a Business Process Flow?

Business process flows provide a guide for people to get work done. They provide a streamlined user experience that leads people through the processes their organisation has defined for interactions that need to be advanced to a conclusion of some kind. This user experience can be tailored so that people with different security roles can have an experience that best suits the work they do.

Business Process Flows are used to define a set of steps for people to follow to take them to a desired outcome. These steps provide a visual indicator that tells people where they are in the business process. Business process flows reduce the need for training because new users don’t have to focus on which table they should be using. They can let the process guide them. You can configure business process flows to support common sales methodologies that can help your sales groups achieve better results. For service groups, business process flows can help new staff get up-to-speed more quickly and avoid mistakes that could result in unsatisfied customers. To find out more, refer to Business process flows overview — Power Automate | Microsoft Docs.

Context

Here we have a Phone to Case Process that consolidates cases raised by our customers in our fictitious company. On the Customer Service Hub, we can see the details of a case such as the Case Title, Customer, Origin, Product in which the case is referring to and the status of the case.

Near the top, we can see a visual timeline of our Phone to Case Process that illustrates 4 key milestones — 1) Identify, 2) Reminder, 3) Research and 4) Resolve. Those stages represent individual and sequential steps of a case from the point of customer escalation to case resolution.

Those stages of a Business Process Flow can be configured by navigating to the Business Process Flow tab in the Power Automate portal.

As we can see, we are presented with the same 4 stages in the flow — Identify, Reminder, Research and Resolve.

Through the Customer Service Hub, we can easily advance the status of a case by interacting with the graphical interface of the portal. For example, by clicking on the Identify stage in the Phone to Case Process timeline, we are presented with a pop-up. After providing the necessary data in the stage and clicking “Next Stage”, we can see that the case has been advanced to the Reminder stage.

Similarly, the case can be further advanced to the Research or Resolve stage using the same mechanism.

However, what if we want to do this programmatically using a Power Automate flow?

What we’d be building

In this guide, we will build an instant Cloud Flow with Power Automate that is manually triggered and requests for a Case Number of a Phone to Case Process.

With this user-provided Case Number, our flow will proceed to locate the case in question and advance the status of the case forward by 1 stage.

For example, if the status of the case is currently in Identify, running the flow will advance the case forward to Reminder. If the status of the case is currently in Research, running the flow will result the case in the Resolve stage.

Let’s get cracking!

Prerequisites

This section establishes some prerequisites we would need to accomplish the task.

Prerequisite 1: Sample Case and Case Number

Firstly, to facilitate the creation and testing of our flow, we would need a sample Case created and its associated Case Number. If you don’t have a case created, create a new case by navigating to the Dynamics 365 Customer Service Hub > Cases > New Case.

With your sample case created, note down its associated Case Number as we will need it later to locate the record. In our case, it would be “CAS-01501-V6M8S3”

Prerequisite 2: Identify the stage ids for your different stages within the Business Process Flow.

In our case, our Phone to Case process has 4 stages — 1) Identify, 2) Reminder, 3) Research and 4) Resolve. Each stage comes with their respective stage ids that we need to refer to within the build.

To extract the stage ids of your associated stages, you would require:
1) Dynamics 365 Portal URL
2) Process ID of your Business Process Flow

They can be located by navigating to the Business Process Flows tab in the Power Automate portal.

The URL of your Dynamics 365 Portal can be found within the URL of your Business Process Flow from the start to “.com”. In our case, our Dynamics 365 Portal URL is https://org161550a5.crm5.dynamics.com/

The Process ID of our Business Process Flow (in our case, our Phone to Case Process) can be found towards the end of the URL from “=”. In our case, our Process ID is 0ffbcde4–61c1–4355-aa89-aa1d7b2b8792

With the above, assemble the following command <Dynamics 365 Portal URL>/api/data/v9.1/processstages?$select=stagename&$filter=processid/workflowid eq <Process ID of your Business Process Flow>.

In our case, our command will be as follows:

https://org161550a5.crm5.dynamics.com/api/data/v9.1/processstages?$select=stagename&$filter=processid/workflowid eq 0ffbcde4–61c1–4355-aa89-aa1d7b2b8792

Enter the command into the address bar of a new browser. You will be presented with a JSON payload as follows.

The individual stage ids for your stages can be found embedded within the keys “processstageid”. Record them down into a notepad.

In our case, the process stage ids for our respective stages are as follows:

#    Stage                   Stage ID                
--- ---------- --------------------------------------
1 Identify 15322a8f-67b8-47fb-8763-13a28686c29d
2 Reminder 88d06f32-3718-4342-bfcd-8e4166e31de2
3 Research 92a6721b-d465-4d36-aef7-e8822d7a5a6a
4 Resolve 356ecd08-43c3-4585-ae94-6053984bc0a9

Mechanism

The Instant Cloud Flow accomplishes this task with the following 6 steps:
1) Create an Instant Cloud Flow with Manual trigger with 1 user input of Case Number (string)
2) Initialisation of multiple variables
3) Identify Case record in our Case table using the Case Number provided by the user
4) Identify Phone to Case Process in the Phone to Case Table using the Case identified in step 3
5) With the Phone to Case Process record identified, we will now identify the current stage of the case. E.g. Identify/Reminder/Research/Resolve. With the current stage, we will construct the resultant stage to advance the case towards
6) Finally, we will move the stage forward by updating the Phone to Case Process record in our Phone to Case Table — using the different variables gathered from Steps 1–5.

Step-by-Step Guide

Step 1: Create an Instant Cloud Flow with Manual trigger with 1 user input of Case Number (string)

Start by navigating to the Power Automate Portal using the link Power Automate | Microsoft Power Platform. Click on Flows on the left side panel.

At the flow page, click on + New Flow > Instant Cloud Flow

A pop-up window should appear. Give the flow a name such as “Advance Stage of Business Process Flow”. Select Manually trigger a flow and click on Create.

You will now be taken to the logic flow editor. Click on + Add an input in the trigger box and select the Text option.

Select Text and insert “Case Number” into the variable name.

Step 2: Initialisation of multiple variables

This step involves the declaration of the following variables:
1) vProcessDetails
2) vTravserPath
3) vProcessStageID
4) Identify Stage ID
5) Reminder Stage ID
6) Research Stage ID
7) Resolve Stage ID

Following the previous step, Click on + New Step, and search for the “Initialize Variable” operation.

Enter “vProcessDetails” for the variable Name, and select String as Type. Leave the Value blank for now.

Repeat this process for vTravserPath and vProcessStageID variables. Ensure that they are of the String type with its Value kept empty.

To initialise our stage ids previously extracted during the prerequisite stage of this tutorial, click on + New Step and search for the Compose operation.

Enter the stage id of the first stage (Identify) previously extracted.

Click on the 3 dots on the top right corner of the operation and rename the operation from “Compose” to “Identify Stage ID”.

Repeat this process for the other stages in our Business Process Flow. The end result should be as follows.

Our current progress should look like this

Step 3: Identify Case record in our Case table using the Case Number provided by the user

In this step, we will list all records in our Case table using the Case Number provided by the user in the very first step. To do that, click on + New Step and search for List Rows under the list of actions available for Microsoft Dataverse.

Within Table name, select the Cases table.
For Filter rows, enter “ticket number eq ‘Case Number’”. This step filters our result through a match with the case number. Note: remember to include single quotations (‘’) surrounding the Case Number Dynamic Content for this to work properly.
For Sort By, enter “createdon desc”
Finally, for Row count, enter “1”

Step 4: Identify Phone to Case Process in the Phone to Case Table using the Case identified in step 3

Following the previous step, start by clicking on + New Step and search for List Rows under the list of actions available for Microsoft Dataverse.

Within Table name, select the Phone to Case Process table.

For Filter rows, enter “_incidentid_value eq CASE”. This step aims to locate our Phone to Case Process record through a match with the incident id from the Case record located in the previous step.

Step 5: With the Phone to Case Process record identified, we will now identify the current stage of the case. E.g. Identify/Reminder/Research/Resolve. With the current stage, we will construct the resultant stage to advance the case towards.

Before we identify the current stage of a case, we have to understand that a case can be in one of 4 stages — 1) Identify, 2) Reminder, 3) Research and 4) Resolve. The current stage of the case also influences the resultant stage of the case as a result of this flow. For example, a case that is currently in the Reminder stage will be advanced to the Research stage, while a case that is currently in the Identify Stage will be advanced to the Reminder stage. To successfully accomplish this, we will employ the Switch operation.

We begin by clicking on “Add an action” following the previous step, and search for the Switch operation

Within the “On” field in the Switch operation, look for the dynamic content of Active Stage (Value). This step establishes different set of operations to happen based on the current stage id of the case in question.

Navigate to the first case in the switch operation by clicking on it.

Within the Equals field, copy and paste the stage id of our first stage — Identify. The following set of flow actions will be carried out if our case is in the Identify stage.

Add a new step by clicking on Add an action, and search for Set Variable.

Select the variable vTravserPath previously initialized and set its value to the Dynamic Content of Traversed Path

Add another action and search for Set variables. This time, select the vProcessDetails variable and sets its value to an Expression with a formula as follows:

concat(variables(‘vTravserPath’), ‘,’, outputs(‘Reminder_Stage_ID’))

Take note that the second variable to be concatenated with our vTravserPath represents the next stage of our current stage of the case in question. In our case, we are currently in the Identify stage and we want the flow to advance the case forward by 1 stage — resulting in the Reminder stage.

Lastly, add another action and search for Set variables. This time, select the vProcessStageID variable and enter the Dynamic Content of the outputs of the resultant stage. In our case, we will select the Reminder Stage ID outputs for the current stage of Identify.

Your current progress will be as follows:

At this point, we will repeat the process for the subsequent stages. As we have 4 stages in total, our flow should account for the following 3 cases:
1) Cases in the Identify stage will be advanced to the Reminder stage
2) Cases in the Reminder stage will be advanced to the Research stage
3) Cases in the Research stage will be advanced to the Resolve stage

At the end of this step, your progress should be as follows:

Note: As you can observe from the Switch operation, this build does not take into account of cases in the Resolve stage. Of course, you can add in an additional case to handle it to either route the case or simply remove it — let your creativity run wild!

Step 6: Finally, we will move the stage forward by updating the Phone to Case Process record in our Phone to Case Table — using the different variables gathered from Steps 1–5.

At this point, it’s time to finally advance the stage of our case by updating our record in the Phone to Process table. Start by adding a new action and search for the “Update a row” operation under the list of actions available for Microsoft Dataverse.

Select the “Phone to Case Process” Table name and click on “Show advanced options”

For Row ID, enter the Dynamic Content of Phone to Case Process Instance Id

For Active Stage (Process Stages), enter the /processstages/vProcessStageID

For Active Stage Started On, enter the expression of utcNow()

For Incident (Cases), enter /incidents/Case

For Traversed Path, enter the Dynamic Content of vProcessDetails

Once you’re done, the operation will look as follows

Conclusion: Now with all the operations within the flow established, your flow should resemble the following. Save the flow by clicking on the Save button at the bottom.

Once the flow is saved, we are ready to test it out!

Testing our Flow!

Open another browser tab and navigate to the Customer Service Hub and go to the sample case created for this demo. Our sample case is one in the Identify stage associated with the customer Claudia Mazzanti. Copy the Case Number presented in the portal.

Navigate back to our flow and click on Test

Select Manually and click on Test

Enter the Case Number previously copied from our sample case. Click on Run flow.

Click on Flow Runs Page to witness the status of our running flow.

Navigate to our sample Case on the Customer Service Hub and refresh the page.

We can see that the status of our sample case has now been advanced to Reminder.

Navigate back to the flow and run it again.

We can see that the status of our sample case has now been advanced from Reminder to Research.

Go ahead and run the flow again to advance our case to the Resolve stage!

Resources

--

--

Responses (2)