Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Triggers
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
  • Get help with flow
Menu

How to send an instant message when your Power Automate flow failed

Posted on May 9, 2021January 5, 2022 by Tom

“I need to know asap if my Power Automate flow failed, I can’t wait a week for it to send a report message or check daily the flow run history.”


One of the Power Automate features is a basic error handling process, a weekly email that will show you all the failed flows from the last week. You don’t need to configure anything for this email, the Power Automate platform sends it automatically.

But I think it has too many limitations. Firstly, only the main flow owner receives the email, not all owners. Secondly, it contains only the flow name and number of failed runs, without a link to the runs. And thirdly, it’s sent only once a week. Not many users are willing to wait for more than a week for a single flow run. That’s why it’s better to manually add an instant error message into your flow.

Enclose your flow in ‘Scope’ action

The most important action for error handling is the ‘Scope’ action. It’s an action to encapsulate other actions, allowing you to create multiple logical sections in your flow. For the error handling you’ll need 2 of them, one ‘Scope’ for the flow and one for the ‘Error handling’.

‘Scope’ with flow

The first ‘Scope’ action should contain your whole flow, excluding ‘Initialize variable’ actions (they must be on top level). The benefit of this approach is that you don’t need to check every action separately. If the actions are in a ‘Scope’, you can check just the ‘Scope’ status to see if any action has failed.

As an example, if ‘Get items 2’ or ‘Get user profile (V2)’ action below fails, the whole ‘Scope – Flow’ action will fail.

‘Scope’ for error handling

Once you have the whole flow in the ‘Scope’ (- Flow), you can add the second one for error handling.

You must ‘Configure run after’ for ‘Scope 2’ (- Error handling) to run only if the ‘Scope’ (- Flow) has failed. That’s only if any action in the ‘Scope’ (- Flow) failed. It’s the same setting you can use as a workaround to disabling part of a flow, but this time it’s used for the intended purpose.

Then you can define in the ‘Scope 2’ what should happen next.

Send link to the flow

You can send a link to the flow in an email or as a Teams message with the expression below.

concat('https://flow.microsoft.com/manage/environments/', workflow()?['tags']['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'])
Power Automate send a message with link if flow failed

Send the error information

You can also include name of the failed action and the error message. The result of ‘Scope’ action can be accessed with the result(…) expression.

result('<ScopeName>')

all spaces in the action name are replaced by _, e.g. 'Scope - Flow' will be 'Scope_-_Flow'
result('Scope_-_Flow')

It’ll contain all the actions in the ‘Scope’, the Succeeded, Skipped and Failed ones. Since you’re interested only in the Failed actions, you can filter them out. Take the whole result(…) array and filter only actions with status: Failed.

item()?['status']

‘Select’ only the relevant information from the failed actions: the action name and the error message.

item()?['name']
item()?['error']?['message']

And add the ‘Select’ output into the email or a Teams message.

outputs('Select')?['body']
Power Automate send error message with failed flow information

End the ‘Scope 2’ (- Error handling) with the ‘Terminate’ action.

The last step is to enforce the ‘Failed’ outcome of the whole flow using the ‘Terminate’ action. If you end by sending the message, the whole ‘Scope 2’ (- Error handling) will end with a success. That means that the whole flow will end with a success. But it didn’t end with a success, there was an error during the flow run.

Power Automate end flow with error if flow failed

Summary

When you build a flow you should always consider also the error handling part. It’s never good if other users notice that your flow is not working before you do, and I think that’s exactly what can happen if you rely only on the basic email. That’s why it’s better to add a few more actions to your Power Automate flow to send a message if the flow failed.

The solution above is using expressions to navigate the results JSON action to process the results. It’s a simplified solution to get only the failed action name and the error message, but you can get much more information. If you store the result(…) into a ‘Compose’ action, you can use it as a payload for ‘Parse JSON’ to see all the available data.

But I believe that the most important part is the link to the flow run. You don’t need to search in the run history, you get a direct link that will tell you everything. Just make sure that the recipient of the message is one of the flow owners.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

4 thoughts on “How to send an instant message when your Power Automate flow failed”

  1. Ben says:
    May 11, 2021 at 6:05 pm

    Nice. We use a very similar process but post to a Team, so if multiple staff should be notified, we can just add them to the Team.

    We didn’t have a link to the run itself, though. That is super useful, so I’m going through and adding it to our flows now.

    Reply
  2. Patricia says:
    September 17, 2021 at 5:43 pm

    Very helpful explanation, thank you! I have added this successfully to my flow. Definitely needed as the Microsoft message arrives too late, making the job of finding the faulty run almost impossible.

    Reply
  3. Robson says:
    January 26, 2022 at 4:05 pm

    Genius!!! Very helpful. I am already using this approach!! Thanks

    Reply
  4. Alex says:
    June 22, 2022 at 2:29 pm

    Thank you so much! This has been very helpful!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


NEW! Master the HTTP requests to SharePoint with a new cheat sheet!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Use Power Automate to forward Outlook events upon registrationJanuary 29, 2023
  • Why the condition is false for the same numbers (Power Automate)January 25, 2023
  • How to forward event invitation to other calendar (Power Automate)January 22, 2023
  • Run ‘For selected item’ flow from non-default environment (Power Automate)January 18, 2023
  • Hide button in SharePoint list after Power Automate flow startedJanuary 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes