1 top tip - Get the result of your failed actions

Get the result of your failed actions in Power Automate

Today, I bumped into the result function in Flow. The possibilities that this opens up could be a real game changer!

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.

Failed action in a flow

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 to the user or administrator?

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

Get the error message in a 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.

The result function in a compose action

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.

Two actions inside a scope

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

Result action when multiple actions in a scope

[

  {

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: