Saturday, January 8, 2022

Power Automate: Multiple Approvers Approval Exceeding Threshold

Hello Friends,

Welcome back with another post on Power Automate. Recently, I encountered with a scenario where the client has asked for approval up to 20 levels depending upon the approval limit. Initially, it scared me as the Power Automate supports only 8 levels of nested conditions. The next scary part was that the SharePoint will throw threshold error if I will save all these approvers (SharePoint list does not support more than 12 People Picker in a single view itself) in transaction list as well. Then how, we will achieve this functionality. But the next moment, I clicked a work around. Let me share the same.

  1. I have a master list "ApproversMaster".

  2. The content in this list is-
  3. Here, I have managed 11 level of approvers and their delegates with their respective minimum approval limit. For example, if the requester has submitted a request of $20,000 then Level 1/2/3/4/6 will be the approvers. but if the requested amount is $32,000 then Level 1/2/3/4/5/6/7 will be the approvers. I will take example of $20,000 for this demo as it will skip level 5 and then proceed further.
  4. Now, I have a transaction list "ApproverRequest"-
  5. Now, what we will do is that, the moment submit a request in PurchaseRequest list, a workflow will trigger.
  6. This workflow, will fetch all the applicable approvers from ApproverMaster list based upon Country/State/RequestedAmount.
  7. Then, the workflow will send approval notification to Approver and it's Delegate simultaneously. The moment, request is approved, it will move to next level. If any level needs to be skipped, we have to manage it. So, let's start writing the flow. For this, go to Power Automate and choose an "Automated cloud flow" for "When an item is created".

  8. Choose SiteAddress & ListName (PurchaseRequest).
  9. Then add an action "Get Items" and choose SiteAddress and ListName (ApprovesMaster)
  10. Apply filter upon Country/State/ApprovalLimit as -
    1. (Country eq '@{triggerOutputs()?['body/Country']}') and (State eq '@{triggerOutputs()?['body/State']}') and (ApprovalLimit le @{triggerOutputs()?['body/RequestedAmount']})
  11. You may apply filter upon ApprovalLevel as well.
  12. Save the flow. Now initialize below variables-
    1. blnProceedFurther - Boolean - true
    2. strApproverName - String - Blank
    3. strApproverEmail - String - Blank
    4. strDelegateApproverName - String - Blank
    5. strDelegateApproverEmail - String - Blank


  13. Now we will fetch information for 1st level approver & delegate.
  14. Use "Condition" action and check if ApprovalLevel is equal to 1. The moment you add "ApprovalLevel" field, another action "Apply to each" wraps this "Condition" action.

  15. If the condition is true, then set below variables-
    1. strApproverName - Approver Display Name
    2. strApproverEmail - Approver Email
    3. strDelegateApproverName - Delegate Approver Display Name
    4. strDelegateApproverEmail - Delegate Approver Email

  16. Now check, if blnProceedFurther is TRUE and strApproverEmail is NOT BLANK, then start approval process for Level1. Also update the Name of approver in PurchaseRequest list item. If condition is not satisfied, then you may update the list item that this level is skipped.
  17. Conditions are-
    1. blnProceedFurther is equal to true
    2. strApproverEmail is not equal to null
    3. length(strApproverEmail) is greater than 0
  18. If condition satisfies, update Approver Display Name (strApproverName) in list (PurchaseRequest) for Level1 and then start the approval process.

  19. Now we need to trap the outcome of this approval. For this, we will add another condition to check the "Outcome" value. It will be either "Approve" or "Reject".
  20. If the value of "Outcome" is "Approve" then do nothing.
  21. For other than Approve, we will set blnProceedFurther as false.
  22. Next update the Approval Status and Date in item.


  23. Now, we need to reset all 4 variables containing Approver Name/Email. So that a fresh assignment can be start for next level. 
  24. Now, we need to repeat from Steps 15 to Steps 31 for each level of approval. The only thing we need to remember is to change level from 1 to 2 and so on everywhere till the last level.
  25. The only thing you need to add is - In case of rejection, you need to inform requestor about it.
  26. Now it's time to test. Add a record in PurchaseRequest.
  27. Below is the approvers hierarchy-
  28. Approval mail has been received to both Approver / Delegate Approver-

  29. Delegate approver has approved the request.
  30. As we can see, the flow has updated the information in list item. Now, the 2nd level Approver / Delegate Approver must receive the mail.


  31. Similarly 3rd & 4th Level should also receive mail.
  32. Level 5 should be skipped because it's approval limit is higher than the requested amount.
  33. The workflow worked as expected. It traversed Level 1/2/3/4/6.
  34. This way, we can define any number of levels approval.
  35. Below is the example for case of rejection. I had rejected the request at 1st level itself. As a result, further process got terminated.

With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.