Action function in Power Automate

Most flow developers will know about functions like body and outputs in Power Automate. But how about the actions function?

The Actions function

The actions function is often forgotten about, but it is one of those functions that many have been looking for.

I’m going to introduce the actions function with a small example. All we need to do is create a Compose action and set this to actions(…) where we supply the action name of a previous action.

actions function in a flow

This will now give us something like the following output. At the first moment this may look like a lot of junk. But when you look a bit better, you can now see what the filter input is that you used. Imagine when the input is set using dynamic content then this could be really helpful as the dynamic content isn’t displayed but the actual content is.

{
  "name": "Get_items",
  "inputs": {
    "host": {
      "apiId": "subscriptions/c44298d0-c055-4569-9fb2-6ab8693eb98a/providers/Microsoft.Web/locations/uksouth/runtimes/uk-001/apis/sharepointonline",
      "connectionReferenceName": "shared_sharepointonline",
      "operationId": "GetItems"
    },
    "parameters": {
      "dataset": "https://pieterveenstramvp.sharepoint.com/",
      "table": "cd7bdb5f-8e96-48d6-bd7a-6672e4db4e0c",
      "$filter": "Title eq 'test'"
    }
  },
  "outputs": {
    "statusCode": 200,
    "headers": {
      "Transfer-Encoding": "chunked",
      "Vary": "Accept-Encoding",
      "X-SharePointHealthScore": "2",
      "X-MS-SPConnector": "1",
      "X-SP-SERVERSTATE": "ReadOnly=0",
      "DATASERVICEVERSION": "3.0",
      "SPClientServiceRequestDuration": "201",
      "SPRequestGuid": "f26f7cb6-f1e2-4165-a01f-faa88b3f9143",
      "request-id": "f26f7cb6-f1e2-4165-a01f-faa88b3f9143",
      "MS-CV": "tnxv8uLxZUGgH/qoiz+RQw.0",
      "Strict-Transport-Security": "max-age=31536000",
      "X-FRAME-OPTIONS": "SAMEORIGIN",
      "Content-Security-Policy": "frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com *.powerapps.com *.yammer.com *.officeapps.live.com *.stream.azure-test.net *.microsoftstream.com;",
      "MicrosoftSharePointTeamServices": "16.0.0.20523",
      "X-Content-Type-Options": "nosniff",
      "X-MS-InvokeApp": "1; RequireReadOnly",
      "Timing-Allow-Origin": "*",
      "x-ms-apihub-cached-response": "false",
      "Cache-Control": "max-age=0, private",
      "Date": "Tue, 06 Oct 2020 11:08:16 GMT",
      "P3P": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"",
      "X-AspNet-Version": "4.0.30319",
      "X-Powered-By": "ASP.NET",
      "Content-Type": "application/json; charset=utf-8",
      "Expires": "Mon, 21 Sep 2020 11:08:17 GMT",
      "Last-Modified": "Tue, 06 Oct 2020 11:08:17 GMT",
      "Content-Length": "10834"
    },
    "body": {
      "value": [
        {
          "@odata.etag": "\"1\"",
          "ItemInternalId": "59",
          "ID": 59,
          "Title": "test",
          
...

          "{Name}": "test",
          "{FilenameWithExtension}": "test",
          "{Path}": "Lists/TestList/",
          "{FullPath}": "Lists/TestList/71_.000",
          "{HasAttachments}": false,
          "{VersionNumber}": "1.0"
        }
      ]
    }
  },
  "startTime": "2020-10-06T11:08:17.1857939Z",
  "endTime": "2020-10-06T11:08:17.5451734Z",
  "trackingId": "2e16123e-fe60-4b12-bed4-5ff5d66aa703",
  "clientTrackingId": "08585996243884165910172435366CU16",
  "clientKeywords": [
    "testFlow"
  ],
  "code": "OK",
  "status": "Succeeded"
}

Ok, this can be useful. We don’t only get the output from an action but also the input. Note that there is also a function ActionOutputs that gives you just the outputs section.

But sometimes you just want to be able to get to the input section of an action and with the actions function this is possible.

Actions in a try catch pattern

When we use the actions function in the try catch pattern. We will see some more interesting purposes of the actions function.

Actions function in Power Automate

In the above example the flow is now looking at the Try Scope for the result using the actions(‘Try’) expression.

First of all when things are successful, we will get a message like this:

{"name":"Try","startTime":"2020-10-06T12:38:21.880635Z","endTime":"2020-10-06T12:38:22.240015Z","trackingId":"6bab2a5f-d5ea-4557-a85f-afd0d61ae405","clientTrackingId":"08585996243884165910172435366CU16","clientKeywords":["testFlow"],"status":"Succeeded"}

When the flow fails however we will get some details on the failure.

{"name":"Try","startTime":"2020-10-06T12:39:23.2797385Z","endTime":"2020-10-06T12:39:23.4828665Z","trackingId":"9c59cd4c-cf86-49fc-adab-478e17bb6ee3","clientTrackingId":"08585996243884165910172435366CU16","clientKeywords":["testFlow"],"code":"ActionFailed","status":"Failed","error":{"code":"ActionFailed","message":"An action failed. No dependent actions succeeded."}}

Now if we want more details on the failure we could run the get actions(‘Get_Item’) again to get the failure details. That will give us the following json:

{"name":"Get_items","inputs":{"host": ...,
"body":{"status":400,"message":"The expression \"Title eq 'tes't'\" is not valid. Creating query failed.\r\nclientRequestId: 918d6393-c1c9-4c50-9999-fc78a7629ae0\r\nserviceRequestId: 918d6393-c1c9-4c50-9999-fc78a7629ae0"}},"startTime":"2020-10-06T12:42:09.4998118Z","endTime":"2020-10-06T12:42:09.6404386Z","trackingId":"e5a61d8e-87f2-46d7-b93c-4d3afdb2f4b8","clientTrackingId":"08585996243884165910172435366CU16","clientKeywords":["testFlow"],"code":"BadRequest","status":"Failed"}

So as you develop your flows you could collect all the details of the actions that sometimes fail using the actions function and then filter only the failed actions and send these to your user when your flow needs a bit of help.

Apply to each and the Actions function

You could within Apply to each steps have a compose action collecting the result of one of the stpes in the Apply to each, however you might find that just referencing the apply to each step will give you all the results of the actions inside the loop.

How often do you want to collect all failures inside a loop and only the failures?

You could now even run retries after your apply to each has finished as you collect all the failed items.

The actions function opens up so many possibilities, you just have to find them to take full advantage of this function.

Thoughts on the Actions function

Now we have the exact details of the failure available within the flow itself, all we need to do is inform the people that are interested or trigger our recovery procedures with out flow.

As I’ve mentioned before you can send the url of the flow run to users but wouldn’t it be helpful to also give the reason for the failure? Well now you can with the method shown above.

Do you need any help, as always feel free to hit the chat or leave a comment below.

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

4 thoughts on “Actions function in Power Automate”
  1. Pieter, I second the thanks. Your examples are incredibly useful for my everyday work. P.S. when I read your try/catch post I immediately reworked a lot of our flows and it has been super useful in getting alerted proactively about problems.

Leave a Reply

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

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading