Categories: Microsoft Office 365

Get the result of your failed actions in Power Automate

Today, I bumped into the result function in Flow. We can now collect failed action details directly within the flow and report the failures in flows.

Failures in Flows

When things go wrong in your flow, there are some error message displayed in your Flow Run, however this means that a user needs to go to the flow run and find out where things went wrong.

Quite often a user interested in the problem might not even have access to the flow run. Wouldn’t it be nice if you could send the error message from failed actions to the user or administrator so that failures in flows become more visible?

My regular followers will be aware of the Try-Catch pattern in Power Automate that I cannot stop talking about. The try catch, will already send the URL to the flow run, but now we can enhance this with the details of the failing action.

Collecting the result of a failed action

In the flow below the Compose action is failing. And the Compose 2  action is collecting the error message generated by the first Compose action

Isn’t this what we have been waiting for for a long time?

The Result function

The result function is slightly harder to use than you might hope for. Although when you know how to use it it is easy to implement.

According to the result function documentation, it returns the result of a scoped action.

If you refer to an action that isn’t a scoped  action then  you will see an error like the one below when you attempt to save the flow:

The template validation failed: ‘The workflow action ‘Compose_3’ at line ‘1 and column ‘1671’ references the action ‘Compose_2’ of type ‘Compose’: only the actions of type ‘System.Linq.Enumerable+WhereSelectArrayIterator`2[Microsoft.Azure.Flow.Templates.Schema.FlowTemplateOperationType,System.String]’ are allowed to be referenced by ‘result’ function. ‘.

So what is a scoped action? A Scoped action can be an Apply to each, Until or a Scope action.

This is going to open doors!

In my earlier example, all I had to do is set the Run after settings for my Compose 2 action to include to run on failure of the Scope and my result function can now give me the details of the action that failed.

Time to look at the output form the results function

[

  {

    "name": "Compose",

    "startTime": "2020-03-06T09:42:59.1275689Z",

    "endTime": "2020-03-06T09:42:59.1275689Z",

    "trackingId": "06b9b7cc-f072-46d0-aa4f-b866ce7b2230",

    "clientTrackingId": "08586181191065299168785271735CU71",

    "clientKeywords": [

      "testFlow"

    ],

    "code": "BadRequest",

    "status": "Failed",

    "error": {

      "code": "InvalidTemplate",

      "message": "Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2195': 'The template language expression 'split('tyrewftysdgjfhgjdsgjhdyufy','a')[3]' cannot be evaluated because array index '3' is outside bounds (0, 0) of array. Please see https://aka.ms/logicexpressions for usage details.'."

    }

  }

]
This is great, I’m getting  the results of my compose action inside the scope.
What happens when I have multiple actions inside my scope.

Multiple actions in a Scope

Time to add a second action inside my scope.

I added a Send me an email notification action and in the flow run I can see that this action worked while my Compose still fails.

The Compose 2 action now returns the result of all the actions, including the successful ones.

[

  {

    "name": "Send_me_an_email_notification",

    "inputs": {

      "method": "post",

      "body": {

        "notificationSubject": "Test Email",

        "notificationBody": "Test email body"

      },

      "path": "/sendEmailNotification",

      "host": {

        "api": {

          "runtimeUrl": "https://unitedstates-002.azure-apim.net/apim/flowpush"

        },

        "connection": {

          "name": "/providers/Microsoft.PowerApps/apis/shared_flowpush/connections/shared-flowpush-f471b5e3-04fd-43ff-b943-b4b566dd1dd1"

        }

      },

      "authentication": {

        "value": "*sanitized*",

        "type": "Raw"

      }

    },

    "outputs": {

      "statusCode": 200,

      "headers": {

        "Pragma": "no-cache",

        "x-ms-request-id": "westus:eb24befa-3cba-4ffa-9479-d00dc320e015",

        "x-ms-correlation-request-id": "eb24befa-3cba-4ffa-9479-d00dc320e015",

        "x-ms-flow-mobile-ios-version": "1.3.0",

        "x-ms-flow-routing-request-id": "WESTUS:20200306T094725Z:eb24befa-3cba-4ffa-9479-d00dc320e015",

        "Strict-Transport-Security": "max-age=31536000; includeSubDomains",

        "X-Content-Type-Options": "nosniff",

        "Timing-Allow-Origin": "*",

        "x-ms-apihub-cached-response": "false",

        "Cache-Control": "no-cache",

        "Date": "Fri, 06 Mar 2020 09:47:25 GMT",

        "Content-Length": "0",

        "Expires": "-1"

      }

    },

    "startTime": "2020-03-06T09:47:23.9432031Z",

    "endTime": "2020-03-06T09:47:25.1776008Z",

    "trackingId": "1382cb46-803b-4be1-8697-dc448deaf3e7",

    "clientTrackingId": "08586181188417586183991966894CU91",

    "code": "OK",

    "status": "Succeeded"

  },

  {

    "name": "Compose",

    "startTime": "2020-03-06T09:47:25.2088528Z",

    "endTime": "2020-03-06T09:47:25.2088528Z",

    "trackingId": "0880bf08-aafa-42e2-b43b-ed89e3448e7d",

    "clientTrackingId": "08586181188417586183991966894CU91",

    "code": "BadRequest",

    "status": "Failed",

    "error": {

      "code": "InvalidTemplate",

      "message": "Unable to process template language expressions in action 'Compose' inputs at line '1' and column '2194': 'The template language expression 'split('tyrewftysdgjfhgjdsgjhdyufy','a')[3]' cannot be evaluated because array index '3' is outside bounds (0, 0) of array. Please see https://aka.ms/logicexpressions for usage details.'."

    }

  }

]
That is a lot of json just for the result of 2 actions!

Finding the failed actions

Yes indeed it is, you should however only need the results of the Failed actions. So you could for example run this output through a filter action so that you only get the failed actions returned. Now that we have the data that should be an easy step to take!

Some thoughts

The above idea of collecting the results of the actions should of course be included in the Try Catch pattern, however for the simplicity of this post I decided not to clutter this post.

I also found that the result function only returns 1 level of actions. If you use nested conditions or apply to each steps you might find that you have to run multiple result functions to get to the actual failure.
Share
Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

View Comments

  • Result function only returns 1 level of actions, but the actual error is in further actions. How to get detail of error in further actions.

    • This is indeed one of the limitations. Hence I would only use this where really needed as the error handling becomes a lot of overhead. For general error handling I would use the Try-Catch pattern.

Recent Posts

Using PnP PowerShell with Azure Automation Accounts

In the past I often used Azure Functions to run PnP PowerShell from my flows…

2 weeks ago

How to export and import solutions using flows in Power Automate

Have you ever wanted to export and import solutions using a flow? In this post…

4 weeks ago

2 Ways to insert dates into Excel using Power Automate

Today I looked at how to insert dates into Excel after a while back I…

1 month ago

Sharing flows in Power Automate

Recently I tried to share a flow and I got trial warning. It took a…

1 month ago

There’s a problem that needs to be fixed in Power Automate

Have you ever had your flows showing the following error: There's a problem that needs…

1 month ago

Get started with child flows in Power Automate

Child Flows is one of the subjects that has been on my list of things…

1 month ago
%%footer%%