Skip to main content

Notifications

Community site session details

Community site session details

Session Id : FHFj7DjkI8NKhdZCXMqmuM

Power Automate Errors Logging

MarconettiMarco Profile Picture Posted 23 Aug 2022 by MarconettiMarco 3,812 Super User 2024 Season 1

When creating workflows, we find it very helpful to use error logging to track Power Automate results so they can be supported by a broader audience.


By default, Power Automate will exit the flow at the point of failure. Periodic email notifications will be sent to the owner(s) of the Power Automate. Here you can see a 28-day run history and any run failures.

Note: if a Power Automate fails continuously for 14 days, it will automatically be turned off 

 

So, from my point of view, it’s necessary to log somewhere the errors in order to:

  • Notify periodically (once per day/week) the flow owner or a Team of users, so that they can take action;
  • Enrich the DB that should allow to build Insights.

     

 

There is better way for handle errors and log all Power Automate flow instances to a single place.

In my case, I’m storing the PA errors in a Dataverse Table, but it’s also possible to use for instance a SharePoint List.

Here the steps to be followed:

  • Create a Dataverse table named in my case “Power Automate Errors Logging” from Power Apps
  • Create the following columns and add the to the main Form:
    • “Action”: single line of text;
    • “startTime”: Date and time;
    • “endTime”: Date and time;
    • “Run url”: Url;
    • “status”: single line of text;
    • “statusCode”: single line of text;
    • “Error message”: single line of text;
  • From the already generated Table, create a Model-Driven Apimage-20.png

 

  • Then let’s move to Power Automate: for each PA flow, it’s necessary to add:
    • a first Scope-Try control in which put all the Actions the flow must perform
    • a second Scope-Catch control in which put all the Action the flow must perform if at least one of the Actions included in the Scope-Try control has failed or timed out.

image-22.png

image-150.png

So, click on the “Scope-Catch” 3 dots and select “Configure run after”

Capture.PNG

 

Then, select the options “has failed” and “has timed out”, finally click on “Done”.

image-152.png

 

Within the “Scope-Catch” control, please add in sequence the following Actions:

  • to get the run ID, add a “Compose” action, name it “Compose-WF ID” and put the following expression: workflow()

image-26.png

  • to get the run url, add a “Compose” action, name it “Compose-Run URL” and put the following expression (please change “emea” with your correspondent region): concat('https://emea.flow.microsoft.com/manage/environments/', outputs('Compose-WF_ID')['tags']['environmentName'], '/flows/', outputs('Compose-WF_ID')['name'], '/runs/', outputs('Compose-WF_ID')['run']['name'])

image-27.png

  • to get the “Scope-Try” result, add a “Compose” action, name it “Compose-Scope Result” and put the following expression: result('Scope-Try')

image-28.png

  • to get the result properties, add a “Parse JSON” action, name it “Parse JSON-Scope Result:
    • put the “Compose-Scope Result” outputs in the “Content” field
    • put the Schema by using the function “Generate from sample”. In order to get the full body, please run the flow and get the “Compose-Scope Result” output, copy and paste it in the “Generate from sample” function

image-29.png

  • to get only the failed actions, add a “Filter array” action:
    • From: Body got from the “Parse JSON” action
    • condition: string(item()?['outputs']?['statusCode']) does not start with string('20')

image-153.png

  • to generate a column in the Dataverse table “Power Automate Errors Logging”, add an “Apply to each” control, selecting the Body from the “Filter array” action to be added in the “Select an output from previous steps” field. Into the Apply to each loop add a Dataverse “Add a new row” action, name it “Add a new row-PA Error Logging and put the following values:
    • Name: put the following expression: workflow()?['tags']?['flowDisplayName']
    • Action: put the “name” got from the Filter array;
    • startTime: put the “startTime” got from the Filter array;
    • endTime: put the “endTime” got from the Filter array;
    • Error message: put the following expression: items('Apply_to_each-Add_PA_Error_Logging_row')['outputs']['body']['error']['message']
    • Run url: put the outputs from the “Compose-Run URL” action;
    • status: put the “status” got from the Filter array;
    • statusCode: putt the “statusCode” got from the Filter array.

image-154.png

 

  • finally, within the “Apply to each” control” add a “Terminate” action with status “Failed”.

image-32.png

Here the entire “Scope-Catch” control:

image-155.png

 

Here the output:

image-36.png

 

 

image-37.png

 

Hope it helped!

Thanks for your feedback.

 

@DamoBird365 @Paulie78 what do you think about this topic?

 

My blog site about Power Automate: https://powerautomatejoy.com/

BR,

Marco

Categories:

Comments

  • MarconettiMarco Profile Picture MarconettiMarco 3,812 Super User 2024 Season 1
    Posted 25 Aug 2022 at 05:53:16
    Power Automate Errors Logging

    Hello @takolota ,

    many thanks for your feedback!!!

     

    For sure, in regards of "critical" flows, we can manage the instant Teams/Email notifications, just to be sure that the user is notified and takes actions as soon as possible.

    I'd prefer to store the flow failures somewhere (i.e. Dataverse or SharePoint), in order to:

    • Create a permanent history of flow runs. I can monitor trends and see how often a flow fails. The list also gives me a direct link to each flow history run which can make it easier to track down a particular failure;
    • Keep track (in Dataverse or SharePoint) of the history of actions taken in order to solve the issue. So, in other word, it's possible to assign the row in Active status, and push the user to close the "ticket";
    • Enrich the DB that should allow us to build Logics and Insights;
    • Don't spam users regarding "non critical" flows, in another article I'm going describing how to send periodic email notifications: https://powerautomatejoy.com/2022/07/26/periodic-errors-logging-notification/

     

    I'd love if Microsoft in the next future will release something like a much more consistent report and not limiting, like today, the history to 28 days!

     

    I may not have all the answers, but I'm curious and passionate enough to keep looking for answers and to keep sharing them.


    My blog site about Power Automate: https://powerautomatejoy.com/

    BR,

    Marco

  • takolota1 Profile Picture takolota1 4,859 Super User 2025 Season 1
    Posted 24 Aug 2022 at 21:16:18
    Power Automate Errors Logging

    What are the intended use cases?

     

    I’ve created a pretty simple template for immediately alerting flow owners of failures for less enterprise-level scenarios: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Flow-Failure-Notifications/td-p/1494079

    So in a lot of cases I think it should be the flow owner’s responsibility to troubleshoot errors & ideally one creates their flows in a way where it won’t consistently error to the point where they need a long log of all the errors.

     

    Is this more for monitoring teams of flow builders & keeping failure records for historical analysis, identifying training gaps, & common issues?

    Or could it also be used for other things?

     

    I wonder if Microsoft somehow tracks this kind of stuff across most users.

    It would be interesting if we could see a consistent display of the most common errors across most users on the platform. Then people could better target their content & training aids.