The “append to array variable” action is one of the most used functions on my daily Flows. It’s instrumental when parsing information and keeping the parsed information for later.

Let’s explore it and see how it works.

Where to find it?

To find it, you can search for “Append to array variable” action or go to “Built-in”:

You won’t probably see it in the main options, so you’ll need to expand until you dine the “Variable” group.

Pick “Variable.”

Select the “append to string variable” action.

Here’s what it looks like:

Pro Tip:
Power Automate tends to save the most common actions in the main screen, so check there before going through the complete hierarchy. Also, you can use the search to find it quickly.

Now that we know how to find it let’s understand how to use it.

Usage

To use the “append to string variable” action, you first need to use the “Initialize variable” action to create a variable. After that, you’ll see it in the dropdown by the name you defined.

We define the variable as an “Array” since the action will work only on “Arrays.” If we have another “Integer” variable, for example:

We won’t see it in the options.

Let’s try it with a simple example. Let’s append a string to the array.

The compose action will contain the values in the array to check them. Here’s the result:

Looks good. But what happens when we “mix” values. For example, let’s now add an “Integer.”

Here’s the result.

As you can see, we can add mixed types, and they keep their data type. As you notice above, the second parameter doesn’t have double quotes, meaning that it’s an integer.

It makes sense that it’s allowed since it’s an “array,” meaning that it is a “bucket” where you can dump values, but it’s pretty dangerous if you don’t ensure that the values are always the same. For example, let’s say that we have an array of numbers, and we’re multiplying them to get a new number. The Flow will return an error if one array row is a string. Of course, it can even be a string with only numeric characters, but to Power Automate, it’s a string nevertheless.

Always convert and control the value that is being appended in action. The result must be deterministic; otherwise, you’ll get ugly results like the above or even errors.

Limitations

Similarly, we have a mixed blessing and curse with the “append to string variable” action. Having a mixed bag of types will result in issues and breaking Flows. Even if Microsoft has to keep the “append to array variable” action as is so as not to break compatibility, it will help a lot of people if either:

  1. The action would have an additional parameter with the definition of the type
  2. For example, have another action called “append to an array variable with type” action.

It would force everyone to keep in mind the values by automatically validating the values inserted in action.

Recommendations

Here are some things to keep in mind.

Since we don’t have a type defined, make sure the type is correct.

Since we can’t force that the array only contains “Integers,” for example, we can validate before if the value that we’re going to insert is one.

Validate every value into the array and ensure that they are always the same type. If not, you’ll have breaking Flows when the type is incompatible with any other activity that uses the rows in the array.

Name it correctly

The name is super important since the operation is not very descriptive. For example, having “append to array variable” won’t tell us what kind of value we are appending, the desired result, and the array that is being appended. It would be best to use the comments to provide further information, but the name is used to know what the action is doing without expanding it.

Always add a comment.

As explained before, it’s essential to know a few things:

  1. First, what is the desired output with the append?
  2. Why are we appending?
  3. What are we appending?
  4. What is the type we want to append?

The intention of the action may not be the same; as a result, so we need to define it before we start working on it. You will then know what was intended when debugging a Flow if something goes wrong.

Always deal with errors.

Have your Flow fail graciously and notify someone that something failed. It’s horrible to have failing Flows in Power Automate since they may go unlooked-for a while or generate even worse errors. I have a template, and a template that you can use that will help you make your Flow resistant to issues. You can check all details here.

Am I missing something? Leave a comment or interact on Twitter. Let’s work together to make this reference as complete as we can

Back to the Power Automate Action Reference.

Photo by Ben Harritt on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

Your email address will not be published. Required fields are marked *