Get Approval from inside your Business Process Flow

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. I have previously blogged about replacing Process Dialogs with embedded canvas apps. We are now 2,5 years further so I would like to present my learnings. There are a ton of new features added to the platform which I would also like to explore. As I write more post on this subject I will add them to the list below.

  1. Task Groups help you guide work in Business Process Flow
  2. Set form fields required based on Business Process Flow Stage
  3. Prettify your Business Process Flow by adding a Code Component
  4. Get Approval from inside your Business Process Flow

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”.

Create the flow with the special trigger 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.
Shows the entire Power Automate Cloud flow in an overview.  The trigger is expanded to show we can enter a comment.  The following actions read as follows: Get userid from the user who asks approval;  Update the case status and approve comment;  Get email from the user who needs to give approval;  Start and wait for an approval.
Overview of the flow

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.

Shows the Dataverse action
Get the UserId from the one who called the flow

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.

Shows the Dataverse action
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 the following code:

first(outputs('Get_userid_from_the_user_who_asks_approval')?['body/value'])?['systemuserid']

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.

Shows the Dataverse action
Get email address from the approve

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.

Show the action
Start the approval

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:

first(outputs('Get_userid_from_the_user_who_asks_approval')?['body/value'])?['fullname']

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”.

Shows the Business Process Flow Stage where we have added the Ask for Approval Flow.
Add the Ask for Approval to the BPF Stage

Publish and activate the Business Process Flow and see it in action!

Shows an animated gif where in the case record we call the Approval Flow inside a Business Process Flow.  And that after a refresh of the form the case is updated with the information from the Approval Flow
Approval Flow inside the Business Process Flow 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!

The post Get Approval from inside your Business Process Flow appeared first on Power Addict Ben.

.

Leave a Comment