How to pass an array from PowerApps to Power Automate

Do you have the following requirements?

  • You want to pass an array from a Canvas App to a Power Automate
  • You want to pass an array from Model Driven apps to Power Automate.
  • You have to parse JSON data in your canvas app and perform further processing.

If your requirement is similar to this, this blog might just help you out. Especially for Canvas app, I find this requirement popping up every now and then. So let’s see how we can solve this. For this blog I have created a simple canvas app which show a list of accounts from CDS. Here I am showing the example with CDS. However the sample example shall work with any other data source.

As you can see from the screenshot below, you can select multiple accounts and then click on “Send to Power Automate” button to send the selected accounts to a flow.

Before we design the Power Automate flow, below is the code on “OnCheck” and “OnUncheck” events of the checkbox.

OnCheck:

Collect(SelectedAccounts, ThisItem)

OnUncheck:

Remove(SelectedAccounts, ThisItem)

Quite simple. I am maintaining a collection here – “SelectedAccounts” which is used to store accounts selected by the user. What’s next then? We need to pass the selected accounts to Power Automate. So let’s create a Power Automate flow.

The flow will be invoked from Canvas app. So it’s quite obvious that the flow trigger should be PowerApps.

In the next step, I use the Initialize variable step. And guess what, I have an option to select “Array” as variable type. Quite easy isn’t it? After all I am going to pass the selected accounts from Canvas app and store in this variable. And logically SelectedAccounts is nothing but a collection of accounts. The value of the Variable I am going to ask from PowerApps.

I save the flow. Now that my flow is created, I wire up the flow with the “OnSelect” event handler of button I previously highlighted on the Canvas app. But when I try to add the flow to my canvas app, I get the below error.

The reason for this is because the Array data type is not supported from Canvas apps. I modify the flow to change the data type of the variable to “String”. Now when I try to add the flow back, I am able to do it successfully.

That’s good. But to how to pass the selected accounts. It’s quite easy actually. We will use the JSON function in canvas apps to serialize the collection into JSON.

ArrayTestFlow.Run(JSON(SelectedAccounts,JSONFormat.IncludeBinaryData & JSONFormat.IgnoreUnsupportedTypes))

In the OnSelect event handler, I invoke the flow with the list of accounts selected by the user.

When I check my flow, I could see the JSON serialized value of my selected accounts.

You may be wondering how to parse this JSON in the flow. Well it’s quite easy. There is ParseJSON step in the Compose Action.

I am passing my selected accounts json in the Content and for the schema, I use the Generate from sample button and provide a sample data to generate the schema.

And then you can use the Apply To Each action, to iterate through the JSON collection.

Below is the output when I run the flow.

As you can see, the five accounts I selected, is now inside the collection that I created using ParseJSON step.

Hope this helped!

You may also like the below posts

Debajit Dutta
(Business Solutions MVP)