Microsoft Power Automate: Multi-Level Approvals integrate with Microsoft Dynamic 365 CRM
I am writing this article to demonstrate Microsoft Power Automate is a very dynamic and vibrant component that automates more complex processes just by configuring the templates with 0% code. The idea is to Create generic Approval flow using Microsoft Power Automate which is capable to handle multi-level approval process like level 1 of approval or level 3 of approval or level 5 of approval and so on. Most interesting part of this article is user can configure Approval Medium. That is When user select Approval Medium field option to Microsoft Outlook then Microsoft Power Automate route the approval process via Microsoft Outlook. Similarly, if user select Approval Medium field option as Microsoft Teams then Microsoft Power Automate route the approval process via Microsoft Teams.
To achieve the above cited use case, I have integrated Microsoft Dynamic 365 CRM and Microsoft Power Automate to do wonders!
Working principle of Approval Process:
Microsoft Dynamic 365 CRM:
Approval Memo Details Entity:
I have introduced new custom entity named as Approval Memo Details which contains essential fields like approver email id, approval level, approval medium, discount amount and total amount etc.
Approved Date: When Approver approved our request, immediately child flow will capture the responded date and update the same in the approved date field.
Rejected Date: When Approver rejected the request, immediately child flow will capture the responded date and update it in the rejected date field.
Comments: Approver comment is captured and updated in the comment field.
Approval Status:
Approval medium: based on the approval medium field value (Microsoft Outlook -1 and Microsoft Teams -2), submit for discount approval flow routes the approval request to either Microsoft Outlook or Microsoft Teams.
Approval Level: User can configure the approval level like level 1, level 2, etc. based on approval level, Approval Memo details records are sorted and processed one by one for the approval.
Approval Memo Details Configure:
User can configure Approval Memo details records for multi levels of approval against quote in Dynamic 365 CRM. For example, I have configured three level of approval memo details records for an approval process. By entering essentially details like approval email id, approval medium, approval level etc. But Total amount, discount and markup details fields are auto populated from quote when record gets saved.
Approval Memo Details configure in action:
Microsoft Power Automate: Submit for Discount Approval:
Step 1:
When a record is selected action is the first event in the flow. It is connected to the Common Data Service(CDS) behind the environment it is running in.
As per our scenario, discount approval process is going to be trigger from quote entity. So, I have selected Quotes in the entity name field.
If we want to pass input to the flow then we can add an inputs. So that when flow is triggered, flow will prompt the user to enter the value in the message box. But in our case, we are not passing any input to the flow.
This action allows the power automate to be appear in the flyout menu in Microsoft Dynamic 365 CRM.
Step2:
Initialize variable is added to store the response from child flow. Child flow response can either be an Approved or Rejected value.
Response variable is initialized by “Approval initiated” value.
Step3:
CDS list records action is added to retrieve all approval memo details records are configured against the quote
Step4:
Condition action is added to check the response variable is equal to “Approved” OR “Approval initiated” AND approval status field value is equal to “Pending”.
Condition action is supported to add multiple conditions. And we can even use expression like And, Or to check multiple conditions.
Approval memo details records are not processed when approval status fields value is equal to “In progress” or “Approved” or “Rejected”.
Similarly, Approval memo details records are not processed when response variable is equal to “Rejected”.
Step6:
In if yes block, I have added another condition to check the approval medium field value (Microsoft Outlook = 1 and Microsoft Teams = 2).
If approval medium field is set to Microsoft Outlook, then approval process is routed to Microsoft Outlook channel. Else the approval process is routed to Microsoft Teams channel
Step7:
Why Child Flows?
If you try to build your complex logic in to a single flow, to put all actions into single flow, it can be difficult to navigate and maintain that flow.
You can use child flows to easily manage flows, avoiding flows with multiple steps. This approach is especially benefit if you to reuse tasks in multiple places in a flow or event across multiple flows.
In our use case, I have created two child flows to inject the approval process either via
Whenever quote is submitted for discount approval, Submit for Discount Approval (parent) power automate will valid the approval medium field. Based on the value, the approval process details are routed to appropriate child flow.
Step 8:
If yes block, Approval process is routed to Approval Process Via Microsoft outlook child flow. Once approver responds to our request. Immediately child flow will return the response to parent flow. Finally, the response value is stored in the response variable.
Approval process via Microsoft Outlook Channel:
If user set the approval medium field to Microsoft Outlook, then approval process is routed to Microsoft Outlook channel.
When the approval medium field is set to “Microsoft Outlook” in approval memo detail record then parent flow will call Approval Process via Microsoft Outlook child flow.
Step 1:
When a HTTP request is received action is used to receive the HTTP request with approval memo details record GUID as a parameter when parent flow calls and send back a response to parent flow as well.
Step2:
Before sending an approval request email to user, the flow will update approval status to “In progress” to indicate that the approval memo detail record is under process
Step3:
Add the “Start and wait for an approval” action and select “Approve/Reject-First to respond” for approval type.
Approval type: When a flow with Create an Approval action is configured with Approve/ Reject – First to respond, it waits until it’s assigned to approve or assigned to reject the approval request.
Title: Discount Approval.
Assigned To: Approver email id is assigned.
Details: discount details that you want sent to the approval.
Step4:
To evaluate the user response is equal to Approve! then we need to add a “condition” to handle the response from the approval.
On the condition card, select an empty area in box on the left. The dynamic content list opens. Select the Outcome parameter to add it to the box.
In the box in the middle of the condition card, select is equal to
In the box on the right, enter the “Approve” text which is mentioned in the approval type.
Step5:
If yes block:
If outcome is equal to “Approve” then add update a record action to update essential field in that approval memo record.
Select Approval Memo Details as entity name. then set the record identifier of the approval memo details to update that record
Scroll down to the approval status field, select the “Approved” option.
For Approved Date field, select it and fill it with the “Reponses Response Date” that you find in the dynamic content pane.
Similarly, for comments field, select it and fill it with the “Responses Comments” that you find in the dynamic content pane.
Send Back Response to Parent Flow: We need to send back response to parent flow. In this case we can use Response action.
We need to decide what response code we want to return. This will differ based on where you use this. For example, if we use this response action in case of some error, then we can return 500 0r 404 if something was not found.
In our case, I’m returning 200 OK and “Approved” text of my message and sending back to parent flow.
If no block:
Similarly, if outcome is equal to “Reject” then add update a record action to update essential field in that approval memo record. Select Approval Memo Details as entity name. then set the record identifier of the approval memo details to update that record. Scroll down to the approval status field, select the “Rejected” option.
In Rejected Date field, select it and fill it with the “Reponses Response Date” that you find in the dynamic content pane.
Similarly, for comments field, select it and fill it with the “Responses Comments” that you find in the dynamic content pane.
Send Back Response to Parent Flow:
I’m returning 200 OK and “Rejected” text of my message and sending back to parent flow.
In if no block, Approval process is routed to Approval Process Via Microsoft Teams child flow. Similarly, when approver responds to our request. Immediately child flow will return the response to parent flow and the response value is stored in the response variable.
Approval process via Microsoft Teams Channel:
If user set the approval medium field to Microsoft Teams, then approval process is routed to Microsoft Outlook channel.
When the approval medium field is set to “Microsoft Teams” in approval memo detail record then parent flow will call Approval Process via Microsoft Teams child flow.
Step1:
When a HTTP request is received action is used to receive the HTTP request with approval memo details record GUID as an input.
Step2:
Add Update a record action to update the approval status field to “In progress”.
Step3:
We are going to create approval content like title, assigned to, details etc. So, I have chosen the Create an Approval template and configure required information.
Before continuing to configure essential information. Let’s know about the Create an approval template.
Create an approval card is a template for the approval request that’s sent to approver. Configure it in a way that’s useful for your approver.
Most importantly Create an approval actions creates an adaptive card based on configuration information.
Approval type: When a flow with Create an Approval action is configured with Approve/ Reject – First to respond, it waits until it’s assigned to approve or assigned to rejects the approval request.
Title: Discount Approval
Assigned To: Approver email id is assigned.
Details: discount details that you want sent to the approval.
Step4:
Approval Medium field is set to Microsoft Teams option. So, I have chosen “Post your own adaptive card as the Flow bot to a user” Microsoft Teams connector. This connector directs the adaptive card to the concerned member.
Recipient: Approver email id is assigned.
Message: we have passed adaptive card which is created in the previous step.
Step5:
Approver receives adaptive card approval request in Microsoft Teams. Meanwhile the flow needs to wait until approver responds to our request. The Response can be either approved or rejected. So, I have used Wait for an Approval template which halts the flow until approver responds to our request.
Approval ID: I have added dynamic content like Approval ID which gives the ID of the approval.
Step6:
To evaluate the user response is equal to Approve then we need to add a “condition” to handle the response from the approval.
Step7:
If yes block:
If outcome is equal to “Approve” then add update a record action to update essential field in that approval memo record.
Send Back Response to Parent Flow:
We need to send back response to parent flow. In this case we can use Response action.
In our case, I’m returning 200 OK and “Approved” text of my message and sending back to parent flow.
If no block:
Similarly, if outcome is equal to “Reject” then add update a record action to update essential field in that approval memo record.
Send Back Response to Parent Flow:
I’m returning 200 OK and “Rejected” text of my message and sending back to parent flow.
The above cited process is carried out for all the approval memo details records which is configured for an approval against the quote.
Discount Approved scenario in action:
Discount Rejected scenario in action:
Perhaps this article will also give you some inspiration on other ways to make use of Power Automate.