Variables are a great way to keep data between actions and manipulate it so we can use it further down the line. But what about if you need the value of a variable while building an expression, for example? Let’s say that you have an array variable, and you want to know its length to decide where to continue with your Flow. You need the length function, but how do you get the variable’s value? To do that, you need the “variables” function so let’s look at how to use it.

Where to find it?

You can find the “variables” function in every action where a formula is supported. For example, let’s look at a “Compose” action:

As you can see, we can auto-complete by using the “tab” key. Let’s look at how to use it.

Usage

It follows a simple pattern.

  1. String with the name of the variable.

Notice that we’re using the variable’s name, not the action’s name. This is the one of the few exceptions in Power Automate where we reference an action by something other than its name. In contrast, let’s say we want to get a task from Planner. We use the “Get a task” action, but notice how the “outputs” function is used.

We’re using the “Get a task” action to get the values inside it, not another value. This can be confusing for some people so keep it in mind.

Limitations

Depending on the size of your string, your expression may return an error, even if it’s correct. Please note that the expressions have a max size of 8,192 characters. If you have an expression that is even bigger than 1000, I would strongly advise that you break it into smaller, manageable formulas.

Also, you can only get the value from the variable, not set it. To set the value of a variable, you need the “Set variable” action.

Recommendations:

Here are some things to keep in mind.

Don’t nest

There’s no real reason to do it, but if you find yourself in a situation where you have nested “variables” functions in a formula, you should review it and make everything more straightforward. In this case, the expression would not fail as long as the return value of a variable is the name of another. Depending on what you want, it may make sense but be careful.

Always add a comment

Adding a comment will also help avoid mistakes. Indicate why you are using the value of the variable and what is the expected result. It may look obvious initially but will not be in a few months or years. It’s essential to enable faster debugging when something goes wrong.

Sources:

Microsoft’s variables Function Reference

Back to the Power Automate Function Reference.

Photo by Vishnu Mohanan 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 *