Thursday, May 12, 2022

Power Automate: Add Admin As Approver In Case Of Out-Of-Office

Hello Friends,

Welcome back with another post of Power Automate. Sometimes, we have a situation where we have multiple level of approvals. In case, if any approver is out of office or on leave, then the approval process gets halted. Is there any way that we can add an Admin in such scenarios?


The answer is YES with a limitation. If the approver is on leave or Out-Of-Office and he/she had activated Auto Replies then we can achieve our goal. Let's see. I will show here how to find whether approver has activated Auto Replies or not. Based upon that, you can use the feature as per your project requirement. Let's start-

  1. Navigate to Power Automate portal.
  2. Click on "My flows".
  3. Click on "+ New flow" and choose "Instant cloud flow".
  4. Give the flow a name. I am giving "VerifyOutOfOffice".
  5. Choose the trigger this flow as "Manually trigger a flow".
  6. Click on Create.
  7. Now we have an action called "Get mail tips for a mailbox (V2)". It is very useful action. It will give us the information that whether the approver has set any Auto Replies or not. It takes the emails address as input.
  8. You may give email id as static value as well as using Dynamic Expression window.
  9. Save it.
  10. Now, first we will test when our mailbox automatic replies are turned off. I am using my account to show the Test Results. You can give any user email id.
  11. Now go back to workflow and click on Test.
  12. Click on Show raw outputs.
  13. Here, you will find the body >> value. It is having a property "automaticReplies". Presently, it is coming as blank as we have not set any Automatic Replies.
  14. Now, change the settings of your mailbox and Turn on the Automatic Replies and save the settings.
  15. Now again test the flow and click on "Show raw outputs".
  16. As you can see that "automaticReplies" property is now having further sub properties. Out of these, the "message" property is of our use. If there is a message, then it will start from "<div". This is what we can check and use to add an Admin for approval. Even, if the message is not null and have some length then it would also be sufficient to validate.
  17. Now, go back to Outlook settings. Set the time period for which replies to be send. If the Start or End is having current date, then message will reflect in output otherwise no. Let's take 2 more examples-
  18. With current date
  19. Without current date
  20. As you can see, if the Automatic Replies is ON and is not set for current date then we will not get the message in response. For all other cases, we are getting message. With this feature, we can identify if we need to add another approver or not. Now, how to validate this message. For this, use the "Condition" action-
  21. Being the output of "Get mail tips for a mailbox (V2)" action is an array which contain only one object so, we will use index as 0 and then we will check for the property "automaticReplies" and then it's nested property "message". Then check it for NULL.
  22. Next we will check if the length is greater than 0.
  23. Now save the flow and test it again. Right now, I had set Automatic Replies as ON without any time frame.
  24. Now, I am setting Automatic Replies as OFF and again Running the flow.
  25. With all these examples, we have now the clear picture that if the message is there, it means the user is on leave / out-of-office.
  26. Now, we can put our logic to add another approver.
  27. This is how, we can trace the availability of any approver.
  28. Limitation: However, the Automatic Replies are meant only to use during Leave / Out-of-Office; in case, if any user is using to send a default reply, then even, the user is available, the flow will assume that the user is on leave because the automaticReplies/message will return a valid message.
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.