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 Ap

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


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

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

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()

- 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'])

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

- 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

- 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')

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

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

Here the entire “Scope-Catch” control:

Here the output:


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