Select to view content in your preferred language

Flow error/fail to run notification

39
1
6 hours ago
ModernElectric
Frequent Contributor

Good day.

I have a series of Power Automate flows for our Survey123 platform. Many of the Survey123 reports that are submitted are time sensitive and are required in order to proceed with other task(s) within the company. 

There are times that a flow fails to run and I am not aware of it until management complains that they haven't seen a specific PDF report.

Trying to come up with a solution that I am notified (E-mail) if a flow fails and/or a nightly E-mail log/report showing the successful completion of all flows and any failed/error flows.

Any guidance would be appreciate.

0 Kudos
1 Reply
abureaux
MVP Frequent Contributor

Scopes! You want Scopes.

They are a little unassuming, but super important for a healthy flow.

How Does Power Automate Interpreter Failures

First, we need to understand how a fail works in Power Automate.

  • Let's say we have a flow with four components labelled A, B, C, and D
  • In this flow, D is our final step and an email to the client
  • We want to be notified if something breaks, so we drop in step E and set its "Run After" to "Fail"
  • Then we run our flow and step B fails

In this scenario, we will not trigger our step E. That is because Step B failed, and everything after it was actually "Skipped". That is where Scopes come in. If anything inside a Scope fails, the entire Scope fails.

How to Set Up Error Handling in Power Automate

As I've already mentioned, scopes. You want to put your entire flow into one scope, and your error handling into a second scope. The only exceptions being: 1) Initialize Variable cannot be added to a scope (super annoying), and 2) Flow Trigger (this one makes more sense).

abureaux_0-1763395297830.png

Nomenclature

This type of setup is normally referred to as "Try" and "Catch", where Try is your workflow, and Catch is your error handling. 

Terminate

When you do this type of setup, you need to guide Power Automate a little. When your error handling executes successfully (as it should), your flow will actually register as a success. This makes looking at your flows in Power Automate annoying. To solve this, always ensure the final step of your Catch is a "Terminate" (set to either Fail or Cancelled depending on your needs -- I go with Fail because I use Cancelled for other things).

abureaux_1-1763395696734.png

What Should Go Into a Catch?

It really depends on your needs. What you see above is a relatively "normal" Catch that I use. In fact, I probably have a good couple hundred flows with this general set-up.

  • Compose - This calculates and formats the difference in time between the start of my flow and this point in the flow. This gives me a "flow run duration" which can help me triage my Inbox at a glance. If you are curious, this is the formula I am using:
    dateDifference(variables('flowStart'), formatDateTime(utcNow(), 'yyyy-MM-dd HH:mm'))
  • Delay - This ensures that I don't create a backlog. Basically, when there is a failure early on in a flow, there is a chance that it resets so quickly that it ends up being the next thing to be processed. If there are a bunch of things needing to be processed, this can create a backlog. I don't always use a delay, but this flow in particular is trigged at least 600 times per day, so delays are a real concern.
  • Send email - this sends me an email letting me know that there is an issue. This is a key component to the Catch, and I go into it more below
  • Update Item - All my flows run in two parts: Part 1 grabs items from my Esri Portal and dumps them into SharePoint (aka my "Router"), and Part 2 sequentially grabs items from my Router for processing. This step re-sets the item in the Router so if can be re-processed. Basically, I try to be as hands-off as possible in my workflows. I have better things to do with my time.
  • Condition - I can end up with 4-5 of these. These just delete items from databases if my flow got that far. Basically, when something goes wrong, I get rid of or reset the additions it made, or else I'd end up with duplicate data when the flow re-runs.
  • Terminate - Another key component to the Catch. You need this.
Error Email Contents

When something goes wrong, you will want to go to that flow to assess the problem and potentially make a correction. Add this to the email (as an expression):

concat('https://emea.flow.microsoft.com/manage/environments/', workflow()['tags']['environmentName'], '/flows/', workflow()['name'], '/runs/', workflow()['run']['name'])

 Here is what it looks like in the flow:

abureaux_2-1763396461404.png

You can pretty it up and add more content if you want. But this is the absolute minimum you need.

Conditions

In case you want to reset other databases, here is how I use contions...

Step 1: Initialize Variable

Just make a boolean and set it to false (technically not required to set it to false, but it helps keep things simple for future you).

abureaux_4-1763396575389.png

Step 2: Set Variable

Do this immediately after the thing you are going to reset. In this example, I set if after my SharePoint Create Item.

abureaux_5-1763396612500.png

Step 3: Condition within the Catch

The condition ensures you don't try to reset something that doesn't need to be reset. As simple as that.

abureaux_3-1763396559000.png