Advanced Techniques for Handling Errors within Power Automate Flows

Power Automate Advanced error handling

Power Automate Advanced Errors Introduction

With smaller few action flows it is much easier to add additional actions to run after action failed to send an email if the preceding action fails, with larger flows this is a bit more complicated as any of the actions could fail and the reporting by email will not clearly identify the problem, in the this blog we will look at how to generate an email detailing the reason for the flow failure and group all actions together so we can create the error handling based on multiple actions using the scope function. 

 

First of all we want to group all of our main actions within a Scope, Note you cannot add initialise variable actions inside of a Scope you can set a variable inside but just not initialise these need to sit outside of the Scope.

Now that all your main flow actions are stored within the initial Scope we want to add another scope to catch any errors which have happened inside of the first scope. 

Ensure to set the second scope to only run when the above action (Try – Scope) fails or times out so we only get notified when the flow run fails, demonstration of this below. 

 

Power Automate using Scope
Setting the Catch scope to only run when the try scope has a failure
Add the expression to the catch scope

Next inside the second scope the Catch Scope (as we have labeled it) add a filter array action with the following two expression’s as shown:

result(‘Try-Scope’
If you have not renamed your scope action it will be 
result(‘Scope’)
item()?[‘Status’]
Make this equal to Failed as demonstrated on the screenshot
Catch all the failures from Scope and filter out only the failures
Power automate, flow to Get the Status with this expression
Create a HTML table with the error details

Next create a HTML Table with the outputs from the filter array action and under the advanced options add the header and values as per below: 

item()?[‘name’]

item()?[‘error’]?[‘message’]

 

 

Finally we want to email the admin or person responsible for fixing the error on the flow, so add the last action of send email, 

Add in the email addresses of the people who should recieve this notification, then add in the subject and in the body section add the outputs from the Create HTML table action.

If you want to add a direct link to the flow use the following code to Create a link to the flow

concat(‘https://make.powerautomate.com/environments/’, workflow()?[‘tags’][‘environmentName’],’/flows/’,workflow()?[‘name’],’/runs/’,workflow()?[‘run’][‘name’])

Power Automate Email Logic
Power Automate-Using Scope Full catch Scope Logic

Conclusion 

Using advanced error handling techniques is particularly important if the flows are running with a service account, where the service account mailbox is not actively monitored, although the methods discussed can be applied to all flows to ensure better error reporting, but the best error handling technique is to error proof the flow, basically when a flow fails and you have figured out why it has failed put some fix in place based on why it failed, for example if it failed because the flow required an active email address to send an approval but didn’t receive one, then add a condition to verify the email address before the approval step then if it doesn’t have one don’t send the approval send an email to a named mailbox informing them.

Error handling is of utmost importance in Power Automate, and leveraging the Scope action allows you to compartmentalise and manage errors efficiently. With proper error handling in place, you can enhance the robustness and dependability of your workflows, enabling smoother and more successful automation experiences. 

Read more about basic error handling within flows here.

Please refer to the official Microsoft Power Automate documentation for the most relevant and up to date information, especially if you have errors after following this guide as Microsoft may have changed functions, connectors or actions from the time of writing this blog. 

One final note about troubleshooting flow runs, consider using the Terminate action in between problem actions in order to stop your flow running the entire way through, this is very useful.

For example you have a flow with 15 actions and one of the actions is to notify all senior leadership team or send approvals and whilst troubleshooting an issue on the flow you do not really want to be accidentally messaging them or sending them duplicate approvals.

Add the terminate function before that action then you can run the flow without it hitting those actions and identify the problem add in a fix then remove the Terminate action. 

Need more Help with Power Automate?

Do you need some further support handling errors on your Flows?

Do you have a Flow you would like to build but unsure how to start?

You can book hours with our power platform consultants who will either set up the Flow for you, fix errors with existing Flows or walk you though the process end to end