For some time now we can call Power Automate Flows inside a Business Process Flow Stage. This is perfect for a lot of scenario’s. With this you can automate certain actions. For example we can connect to another system and update inventory. Or we can send e-mail follow-ups to other departments. Or, my favorite, we can start an Approval Flow! In this blog post I’ll share a few of my tricks.
This blog is part of a series about guiding users and teams through their work. This post is about Approval Flows inside Business Process Flows. Click here for an overview of all related post regarding Approvals inside your Business Process Flow. I also added a sample solution you can import in your own development environment so you can see the entire concept in action!
Keeping people in their flow of work by utilizing Asynchronous work or asynchronous processes is one of the key benefits for Business Process Flows. I have written down my thoughts on this subject here. Find out what asynchronous work is, how Business Process Flow can help and more advanced scenario’s.
Create the Approval Flow
Imagine a scenario where we are working an incident reported by one of our customers. They accidentally dropped their new phone which they recently bought from us and now their screen is cracked! In our system we can see that this customer is quite loyal. As the case worker we think they qualify for an immediate replacement of their screen. However it is policy that we ask for approval before we continue to do so. In this case an approval flow inside a Business Process Flow makes perfect sense!
There actually is documentation on this exact subject written by Microsoft. However this is a bit outdated. For example it shows that you need the Parse JSON action to use metadata from the Flow. which is no longer needed as their now is a special trigger available. So let’s go ahead and create our approval flow. Make sure you create the flow inside a solution else the trigger we need will not be available. The Microsoft Dataverse trigger is called: “When a flow step is run from a business process flow”.
What I want to do in my scenario and my flow is of course Ask for an approval. But I also want to track the approval request and the progress inside the Case record. For this I added the following columns to the Case table:
- Approver. A lookup to the User inside our environment we want to ask the approval of.
Tip: Try to automatically (or programmatically) fill in who needs to Approve. For example based on the Case type.
- Approval request. A text field where we store the actual request.
- Approval requested by. A lookup to the User who makes the request.
- Approval result. A choice field to store the status of the Approval.
- Approver comment. A text field where we store the comment of the Approver when he accepts or rejects the Approval.
Get the Dataverse UserId from the Flow CallerId
To keep track on who asked for the approval for this case, I want to update the approver column. With the trigger “When a flow step is executed” we get a set of meta data of the Power Automate Flow. One of these is the “UserId”. However this is not the Dataverse UserId. This means we can not use this to fill the look-up directly. The UserId from the metadata is actually the Azure Active Directory Id of the user. Luckily this id is available to us as an column inside the User (systemuser) table inside Dataverse.
We use the Dataverse Action “List rows” and set a filter with “azureactivedirectoryobjectid eq UserId” to accomplish this. Note that I only select the columns systemuserid and fullname. It is good practice to keep the columns to a minimum as this will improve performance.
Now that we know who the user is who initiated the flow we can update the Case record. Thanks to another meta data attribute “BPF Flow Stage Table Row Id” we update the case.
We fill in the Comment send in the Business Process Flow Stage at the Approval Request. We set the column Approval result to “Waiting” and fill the Approval request by Lookup with following code:
Start the Approval process!
Before we start the Approval process we need an email address. Inside the model-driven app on the form the user selects who can approve the request. After the update of the record in the action above we automatically get all the values of the record we update. We use the value of the Approver to get the User using the Dataverse action “Get row by Id”. Again we only select the column we need, in this case the internalemailaddress.
Now we can start the approval by using the action “Start and wait for an approval”. We choose the Approval type “Approve/Reject – First to respond”. We assign the Approval to the User by the e-mail from the action above and in the Details column we add the Comment from the Approval request.
In the Title we add the name of the Business Process Flow for some context. And we add the fullname of the User who asks for Approval with the following expression:
The result of the Approval Flow so far
Now save the Flow and add it to your Business Process Flow. At the Business Process Flow designer you can add the Flow Step to your stage. You can only select the flows which use the trigger “When a flow step is run from a business process flow”.
Publish and activate the Business Process Flow and see it in action!
I think adding an Approval flow to a BPF works great. It helps to bring someone in to take a look at the case you are working on. However this is not the final result. We of course want to capture the response of the Approval as well. Also we need to look at the “Item Link” functionality of the Approval action. It would be great if we can add a direct link to the Approval flow. As this post is already a bit lengthy, I leave that for my next post!