Get email alerts with direct links to the flow run any time your flow fails by adding this set of actions to the end of your flow.
Either download the template attached to this post & copy the Scope in the template, or copy the Scope action's code, navigate to the My clipboard tab on a new action and press Cntrl + V to get this Scope as a new action option.
Scope Code To Copy & Paste Into Your Flow
{"id":"fd3dfdb1-5fc7-4bb4-b830-978bffcb68b9","brandColor":"#8C3900","connectionReferences":{"shared_office365users":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_office365users/connections/4492902ae6154e088865fbb98252807a"}},"shared_office365":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_office365/connections/shared-office365-02d46624-0d5c-40fe-89f0-c5df-8c7ffde7"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Scope_Failure_Notifications","operationDefinition":{"type":"Scope","actions":{"Compose_Flow_run_link":{"type":"Compose","inputs":"@concat('https://us.flow.microsoft.com/manage/environments/', workflow()?['tags']?['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'])","runAfter":{},"metadata":{"operationMetadataId":"304e2c8e-c6d8-4bd0-ac4d-57951dd57763"}},"Get_my_profile_(V2)":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_office365users","operationId":"MyProfile_V2","apiId":"/providers/Microsoft.PowerApps/apis/shared_office365users"},"parameters":{},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Compose_Flow_run_link":["Succeeded"]},"metadata":{"operationMetadataId":"16453b92-e67e-40aa-acf4-fbd90183a4f0"}},"Send_an_email_(V2)_Failure_notification":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_office365","operationId":"SendEmailV2","apiId":"/providers/Microsoft.PowerApps/apis/shared_office365"},"parameters":{"emailMessage/To":"@outputs('Get_my_profile_(V2)')?['body/mail']","emailMessage/Subject":"Your @{workflow()?['tags']?['flowDisplayName']} flow failed","emailMessage/Body":"<p>Check your flow.<br>\n<br>\n<a href=\"@{outputs('Compose_Flow_run_link')}\">Flow Run Link</a> </p>"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Get_my_profile_(V2)":["Succeeded"]},"metadata":{"operationMetadataId":"bd4b39c2-3462-4a00-b21d-d8ac056f00d2"}},"Terminate_Mark_flow_run_failure":{"metadata":{"operationMetadataId":"c3050a38-c258-4145-b3fa-4d5e80d70b67"},"type":"Terminate","inputs":{"runStatus":"Failed"},"runAfter":{"Send_an_email_(V2)_Failure_notification":["Succeeded"]}}},"runAfter":{"Compose_(All_Your_Flow_Actions_Here)":["Failed","Skipped","TimedOut"]},"description":"Set this Scope's Configure run after settings to \"has failed\", \"is skipped\", and \"has timed out\".","metadata":{"operationMetadataId":"072e1b99-2b98-4cdc-bb50-f9ef10d9a137"}}}
watch?v=u9GhlSofXAI
@Anonymous
Thanks.
I can't tell you how many times I've needed to use this & end up just Googling & copying from my own thread to quickly add it to my flows.
Despite your great instructions and video, I forgot to set the "run if" condition on the flow failure step.
However it turned out well as it highlighted another problem for my flow, and possibly for others down the line.
In my flow I have two parallel branches, each of which backs up a critical SharePoint list to a csv.
Initially I included your code in each parallel branch, which was fine, until one failed in a test. Problem was that as soon as the flow triggered as failed the whole flow stopped and any unfinished steps were cancelled. If one of my parallel branches was still processing, it would also be stopped.
So I tweaked the steps instead along these lines:
Regarding my step 4, is there an easier way to achieve a nested if behaviour than to literally create nested conditional steps? Something easy like a Switch(True()...)?
Thanks in advance.
EDIT: I realise there is a switch control, however I believe that evaluate only one variable. I'd like to evaluate two.
@Anonymous
There should be a MUCH easier way you just have to understand a little quirk with parallels.
If you scroll all the way to the bottom of the flow, there should be an Add an action option. If you click that it should generate a new action that sll the parallel branches reconnect into once they are done. Put this notification piece there.
Thanks for the feedback again. I do already have the parallels joined afterwards.
What I meant was the nested if that I'm running to determine which email I want to send.
So I either send:
1. Both branches succeeded
2. Both branches failed
3. Left branch failed
4. Right branch failed
I did find some information on using a switch function but from what I've read that will only evaluate a single variable in the switch.
Not a big deal, this is just kind of messy.
@Anonymous
I'm not sure I understand your use-case. Why are you trying to use this set-up in the middle of the flow?
It's meant to go at the very end & just trigger when anything above it goes wrong.
And if you only want to send a failure notification under certain conditions, you can create a conditional in the notifications scope & set whatever conditions you want with as many variables / inputs as you want. Then set one side to trigger the notification steps & the other side to not trigger them.
I'm not sure I understand your use-case. Why are you trying to use this set-up in the middle of the flow?
Well the answer to that is easy... because I'm a Power Automate noob 😅
It's quite possible I pigeon-holed my thought process. I initially wanted to send an email for each branch, so tried to implement your code at the end of each branch. The problem I encountered was that if one side failed before the other finished, it would cancel any unfinished steps in the second side, even if it was other wise working fine. So then I [mangled and] moved your code to the end. The problem I faced then was that if both sides of the flow succeeded, the steps were skipped and it didn't send an email at all. I think this was my major stumble.
I think the main reason I did it this way was because our process requires an email be sent regardless of the outcome. If your section of code does not get triggered and is skipped, subsequent steps are not run.
There's a very good chance I'm misunderstanding something, and I'm hardly up on all the possible functions and applications available in Power Apps.
Hi @Anonymous
One way to check what failed is create a variable called "Result" of type integer, iniatialise as 0. If left fails add a catch that updates Result = Result + 1. If the right branch fails, add a catch that updates Result = Result + 2.
Maybe that could be a way around it.
Then at the bottom, a summary have a switch that says
- if Result = 0, then all succeeded,
- if Result = 1, then LEFT failed,
- if Result = 2, then RIGHT failed,
- if Result = 3, then BOTH failed.
Hi @takolota,
This is super helpful thank you, I have it working fully apart from I am unable to add the termination control step under an action of type 'for each'.
I am using the standard template flow for 'record form responses in SharePoint', is there a workaround to the termination control step at the end that will allow me to mark the flow run as 'failed' in the run history when the e-mail notification of error is successfully sent?
I am very new to PowerAutomate so sorry if I am missing the obvious - I'm hoping there's a way just so if any colleagues happen to check the run history and maybe miss an e-mail notification of a failed flow they are not confused by all the run history saying success,
Thank you,
If the Apply to each loop has any failures, it should still mark the loop action as failed, then trigger the failure notification at the end of the flow outside any loops. It’s only Do Until loops that don’t trigger a failure when one of their loop instances fails.
So you should be able to add the Failure Notifications scope to the end of the flow & include any different failure email recipients as needed. Just like in the video.
Hi @takolota,
Thanks for your reply I have got it fully working now it was my mistake putting the action code in the wrong spot in the chain,
Thanks again 🙂