In Microsoft PowerAutomate (previously called Microsoft Flow), Approvals are a great way to automate the sign-off on a process or document. Approvals can be actioned right in the email in Outlook as well as in the PowerAutomate phone app or in the web portal. Unfortunately, sometimes the email notification for the approval gets overlooked and the approval will just sit there until it times out. In this blog I’ll show you how to create reminder emails that can handle the timeout and progress the workflow without failing it.
The plan is to start a Do Until loop as a parallel branch to the approval step. The loop runs until a variable value shows “complete”. Inside the loop is a delay, then the variable is checked. If the variable value is “pending”, an email reminder is sent to the approver.
When the approval has been processed, the next action sets the variable to “completed”, so after the current delay is over, the loop will end.
This approach is easy to set up, but it has a few issues.
- The delay period must be completed before the loop can be ended. This can lead to undesired lag. For example, if the delay period is one day, the following can happen: The flow sends a reminder email at, say, 1 pm and a new delay is started. The approver actions the approval at 1:30 pm, but the flow will still wait until 1 pm the next day before the loop is ended and the next action after the loop is carried out.
- If despite all reminders the approval times out, the next actions after the approval don’t run. That means the variable never gets set to “completed” and the reminders keep getting emailed until the flow itself times out.
Let’s see how to fix this.
Shorten the delay without spamming the approver
For the first issue, I’ll shorten the duration of the delay and use a counter variable that gets incremented in each iteration of the loop. Let’s say one hour instead of one day (24 hours). We don’t want email reminders to go out every hour, though. The approver would certainly not appreciate getting hourly reminders. I only want to send the email once a day, so before I send the email, I divide the counter by 24 (the number of hours I want to wait between emails reminders) and look at the remainder. If the remainder is zero, the counter is a multiple of 24 hours and the email will be sent. The mathematical term for the “remainder of a division” calculation is the “modulo”. Very conveniently, PowerAutomate has a function to calculate that.
I use that expression in a variable of the data type float and then check if that variable is zero. That way I can see the result of the mod() function in the run history after the Flow has run.
So here is what the Do Until loop looks like now.
Caveat! Be aware that the Do Until action has its own limits for how often it runs and when it times out. The default limits are 60 runs and a one hour timeout. If either of these limits are reached, the loop will end and no more email reminders will be sent. You can change the limits to a higher run count and a different time period, though. Just click the Change Limits drop down. In my scenario, my approval will be set to time out after 5 days, so I’ll set the Do Until to the same timeout limit. The duration is written in ISO 8601 duration format, so for 5 days I need to write P5D. With 24 hrs in a day and hourly delays that means I need a count of no fewer than 120 hours.
Now the progress of the approval is checked every hour and a reminder is sent once a day while the approval is still pending.
Managing the approval timeout
By default, an approval times out after 30 days. It will then vanish from the approval portal page, as if it never happened. The Flow itself also times out after 30 days. When that happens, the Flow registers as “Failed” and conveniently (NOT!!) also disappears from the run history, which keeps only 30 days of Flows.
While you cannot do anything about the Flow timeouts, you can change the approval timeout to something shorter and take action while you are still in control. The timeout can be changed in the Settings of the approval action, which you can find in the three dot menu of the action. Change the duration to the value you want to use and set the Retry Policy to None.
The screenshot shows a timeout interval of 15 minutes, i.e. PT15M, which I used during testing the flow. I later changed it to five days, i.e. P5D to align with the loop timeout.
The next step after the approval is a condition that checks the approval outcome. That will be either Approve or Reject if the approval is actioned in time, but if the approval times out, this next action step does not run unless it is set up with a Configure run after. Click the three dots of the condition step and select Configure run after. Now tick two options, i.e. is successful and also has timed out.
The condition action will now be executed when the approval is completed (a Reject outcome is still a successful outcome). If the approval has timed out, there will be no outcome. I can exploit this behaviour with a nested condition in the No branch. In words: If the approval outcome is “Approve”, send an email with the approval news. Else, if the approval outcome is “Reject”, send an email with the rejection news, otherwise it must be a timeout, so send an email with the timeout news.
This gives me a handle to deal with each outcome differently.
After that, the varApproval is set to “complete” and within the next hour the loop will exit and the Flow can process the actions following the parallel branches.
The nested conditions are not pretty, but this approach works. I tried a Switch instead of a Condition, but the Switch will fail after a timed out approval, since there is no outcome. The Condition handles that scenario much better.
That’s it. We can now send reminders, control the timeouts and process the result of the approval.