November 19, 2024

The “output” function is used to get the values from actions. Similar to how “variables” function but for all actions instead of only variables.

Let’s see how to use it.

Where to find it?

You can find the 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 action

Notice that we cannot use spaces and should replace them with underscores. That’s something defined by Microsoft, and it’s done automatically for you when you reference any value.

We can see the same result when we hover the mouse in the value.

You’re using it without knowing

Actually, when you select any value in the “Dynamic Content” tab, you use an “outputs” function behind the scenes. As I mentioned, Microsoft does a great job hiding this from you, but if you need to build an expression, you know how to do it.

For example, let’s see how to get the length of the title in the previous example. To do that, we need the length function like this:

length(outputs('GET_A_TASK')?['body/title'])

You can get to the formula quickly like this:

Names are case insensitive

Finally, something essential. The names are case insensitive, so:

outputs('GET_A_TASK')?['body/title']

is the same as 

outputs('Get_a_task')?['body/title']

Here’s the output:

It’s strange behavior, but I can understand why Microsoft designed it like this. It’s pretty easy to make a mistake in capitalization, and having Power Automate “compensate” for these errors is quite a nice touch.

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 action, not set it. Most actions are read-only, so if you want to mutate the value, I recommend putting it in a variable and then using the “Set variable” action to change it. Or you can also use a “Compose” action to parse a value inside an 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 “outputs” 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 an action 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 output 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 outputs Function Reference

Back to the Power Automate Function Reference.

Photo by Juan Di Nella 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 →

One thought on “Power Automate: Outputs function

  1. Nice article but im left with a question.
    I’m trying to get an output of one of several actions i used in a switch case but i would prefer to use it just once after the switch rather than once in every single case block.

    What i am trying is outputs(variables(‘VariableName’))?[‘body/responsev2/predictionOutput/labels/…/text’]
    But i always end up with the error “The template function ‘variables’ is not expected at this location.”

    Is there a limitation that you can’t use functions/variables in the action name part of the outputs function?

Leave a Reply

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

Mastodon