Dynamics 365 - Flow - Multilevel Approval Request (Flow)


Microsoft vision is to move towards connected applications. Common Data Model(CDM) is integral part of this vision enabling various applications to sync data to CDM. Microsoft Dynamics 365 and Microsoft Flow and Outlook applications use CDM to communicate. We also have many other connectors available from Microsoft.

Multi-Stage Approval Process:
Scenario:
We will have various scenarios where we need to have multilevel approvals to process requests. For example, we might have a situation where a warranty claim case requires approvals based on the claim amount.

We will now look at the how to send multi stage approval requests for events in Dynamics 365 through Flow to Outlook.

Pre-Requisites: Office 365 account, Dynamics 365 App

   


Let’s assume a Case created in Dynamics 365 requires multilevel approvals. We can use Microsoft Flow to send an email for approval and once approved or rejected, we send an email to the concerned people on the approval status.

Below is a sample case created in dynamics 365.


I assume you know the basic operations in flow to set-up triggers and actions. If not. please see my example on Microsoft Dynamics 365 – Email Approval Request using Flow.
Below is the overall flow process.

Don’t be overwhelmed by the above process, it’s really simple..

Here we will look at 2 stages where in the first stage we look for majority approval and a second stage where we have a regular which can override previous approval status.

Stage 1: (Majority must Approve)
For this, we use a technique where we have a list of approvers and check for counts of approvals responses and decide whether the request is approved or rejected. We need to create a set of variables.
1) Array with approver emails.
Note: We can also get a dynamics list of approvers here but, that’s for a later post.
2)Two Arrays(Empty arrays) for capturing approvals and rejections.
We need these arrays for find counts on approvals and rejections and also to get a list of all approvers who approved/rejected using union.


Here in my case I used the below condition to follow the next steps in the flow. You can have your own conditions as per your needs.
Note: We can use the advance mode to write multiple conditions as below. How to do that is for a later post. 😊
@and(greater(triggerBody()?['new_claimamount'], 5000),equals(triggerBody()?['_statuscode_label'], 'In Progress'))

Now that we have the list with approver's emails and two lists to capture the responses, we need to use ‘Apply to each’ to send approvals. To send the requests in parallel, go to Settings on ‘Apply to each’ and ‘Turn On’ the ‘Concurrency Control’

Now that we have sent the requests for approvals, we need to check for approval responses and add them to appropriate array using ‘Append to Array’ actions. Once we have responses, we can now check for length of each array and decide the overall response.

Note: With this approach we can move to the next step in the process only when all the approvers in the list respond with either 'Approved' or 'Rejected'. We can use a parallel step to run a counter (let's say 2 days) and move on to the next step.




Based on the response we can either update the record in Dynamics 365. This ends Stage 1 approval process.
Now if the overall response is ‘Approved’, we can now go ahead with the Stage 2 Approval process.

Stage 2:
Now this stage is pretty simple where the approval is sent to higher management or an executive as below. 



Here we can also include responses of Stage 1 approvers and also comments of each approver if any. To do this the simple approach is to use JSON variable to record name of approvers, response(approval/rejection) and comments. Also, you might have seen above that we have initialized 3 different variables. We might have a situation where we see a requirement for a lot of variables and this might bloat the whole flow process. One easy step is to initialize a JSON variable and use this variable to capture all the required information.

We will look at JSON variables in another post. 😊

Below is a sample flow email.




Comments

Popular posts from this blog

Dynamics 365 - Dynamically create Custom Lookup View(JavaScript)

Dynamics 365 - Xrm WebAPI

Microsoft Portal JavaScript