Skip to main content
Power Automate
    • Connectors
    • Templates
    • Take a guided tour
    • Digital process automation
    • Robotic process automation
    • Business process automation
    • Process Mining
    • AI Builder
  • Pricing
  • Partners
    • Blog
    • Documentation
    • Roadmap
    • Self-paced learning
    • Webinar
    • Business process and workflow automation topics
    • Overview
    • Issues
    • Give feedback
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • User groups
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Microsoft Power Automate Community
    • Welcome to the Community!
    • News & Announcements
    • Get Help with Power Automate
    • General Power Automate Discussion
    • Using Connectors
    • Building Flows
    • Using Flows
    • Power Automate Desktop
    • Process Mining
    • AI Builder
    • Power Automate Mobile App
    • Translation Quality Feedback
    • Connector Development
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Galleries
    • Community Connections & How-To Videos
    • Webinars and Video Gallery
    • Power Automate Cookbook
    • Events
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Community Engagement
    • Community AMA
    • Community Blog
    • Power Automate Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power Automate Community
    • Galleries
    • Power Automate Cookbook
    • Flow Failure Notifications

    Flow Failure Notifications

    03-09-2022 07:19 AM - last edited 05-06-2022 10:46 AM

    Super User takolota
    Super User
    26765 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    takolota
    Super User takolota
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Flow Failure Notifications

    ‎03-09-2022 07:19 AM

    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.

    Flowfailurpic.PNG


    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.

    FlowFailCopyToClip.pngFlowFailCopyToClip2.png

     

     

    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&colon;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>&nbsp;</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
    FlowFailureNotifications.zip
    Labels:
    • Labels:
    • Automated flows
    • Button flows
    • Desktop flows
    • Scheduled flows
    Message 1 of 45
    26,765 Views
    19 Kudos
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    • « Previous
      • 1
      • 2
      • 3
      • 4
      • 5
    • Next »
    takolota
    Super User takolota
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-23-2022 07:58 PM

    @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.

    Message 21 of 45
    886 Views
    1 Kudo
    Reply
    Anonymous
    Not applicable
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-23-2022 09:56 PM

    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:

    1. Initialise two variables at the start both as false, one for each branch.
    2. At the end of each branch I used the same "run if" conditions you mentioned and have a step to set the corresponding variable to true.
    3. I had to create a dummy "continue" step afterwards with a "run if" condition to run regardless of the step before, otherwise if successful, both branches would terminate, and my next step was skipped completely.
    4. I moved your steps to a gated condition after rejoining my branches. I used your code here and (using a series of nested conditions), evaluate whether one or both of the variables are set to true, and send an email accordingly.

    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.

    Message 22 of 45
    874 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-24-2022 03:48 AM

    @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.

    Message 23 of 45
    859 Views
    0 Kudos
    Reply
    Anonymous
    Not applicable
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-24-2022 04:01 PM

    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

     

    flow.png

     

    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.

    Message 24 of 45
    850 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-24-2022 04:16 PM

    @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.

    Message 25 of 45
    844 Views
    0 Kudos
    Reply
    Anonymous
    Not applicable
    In response to takolota
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-24-2022 04:58 PM

    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.

    Message 26 of 45
    834 Views
    0 Kudos
    Reply
    neilcotton
    neilcotton
    New Member
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎10-25-2022 12:23 AM

    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. 

    Message 27 of 45
    817 Views
    1 Kudo
    Reply
    pigsinblankets
    pigsinblankets
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-01-2022 06:38 AM

    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, 

    Message 28 of 45
    778 Views
    0 Kudos
    Reply
    takolota
    Super User takolota
    Super User
    In response to pigsinblankets
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-01-2022 07:01 AM

    @pigsinblankets 

     

    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.

    Message 29 of 45
    771 Views
    1 Kudo
    Reply
    pigsinblankets
    pigsinblankets
    Frequent Visitor
    In response to takolota
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-02-2022 07:38 AM

    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 🙂 

    Message 30 of 45
    763 Views
    2 Kudos
    Reply
    • « Previous
      • 1
      • 2
      • 3
      • 4
      • 5
    • Next »

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign up free
    • Sign in

    Browse

    • Templates
    • Connectors
    • Partners

    Downloads

    • Mobile
    • Gateway

    Learn

    • Documentation
    • Learn
    • Support
    • Community
    • Give feedback
    • Blog
    • Pricing

    • © 2023 Microsoft
    • Contact us
    • Trademarks
    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Terms & conditions
    Consumer Privacy Act (CCPA) Opt-Out Icon Your Privacy Choices