Compose in Power Automate

In this post, we’ll take a look at the handy compose action, which is one of the data operations, in Power Automate! Stay tuned to hear about 4 other data operations in Power Automate coming this week… Upcoming… Tuesday 24-01-23 – Join Wednesday 25-01-23… READ MORE [https://lewisdoes.dev/blog/co
gold letter y on black background
Photo by Maksim Goncharenok on Pexels.com
In: Low Code Lewis Content 🚀

In this post, we’ll take a look at the handy compose action, which is one of the data operations, in Power Automate! Stay tuned to hear about 4 other data operations in Power Automate coming this week…

Upcoming…

Tuesday 24-01-23 – Join

Wednesday 25-01-23 – Select

Thursday 26-01-23 – Filter array

Friday 27-01-23 – Create CSV & HTML Tables

What is the compose action?

The compose action is one of the data operations we can use in Power Automate. It’s typeless, meaning we can provide it with any type of data as an input, and it will give us back an output after doing anything we ask it to with things like expressions. Compose will effectively tell us what the output will be of some content we give it. If we give it something hard coded as an input, it will simply give us the same thing back. Though, if we use things like dynamic content or expressions in our compose, the outputs of our compose will be the result of whatever that dynamic content or expression is.

The difference against variables and when to use Compose

Variables can be initialised then repeatedly updated in our flow. Compose doesn’t do the same thing. When you have a value that needs to be set once and accessed from anywhere within your flow below your ‘setting’ action, this is when to use a compose. Compose is almost like a constant variable (if comparing to a language like JavaScript), it can only be set once, and cannot be changed after, until of course the flow is run again with new data.

Debugging

A great reason to use compose is to make debugging easier when reviewing your flow runs. Occasionally we have actions in Power Automate that won’t show us their outputs. For example if we use a condition and use an expression in that condition, the output of it will only ever be true or false as to whether our provided value met the condition we specified or not.

By using a compose prior to that to hold our value, we can see the data that was actually used in our comparison once it got to our condition step. This makes finding those things going wrong much easier when debugging our flows.

Where to find compose?

In your Power Automate cloud flow, add a new action. You can now either search for compose, or navigate to the built in connectors/steps, then select ‘Data Operation’, and finally select ‘compose’.

A problem…

Now say for example you’re using a handful of compose actions to see what you’re getting as an output after using some dynamic content or when using an expression, and you’ve referenced all of your compose actions in places in your flow, but now all of those bits of dynamic content all just say ‘Outputs’

This makes it a little difficult to easily see what we’ve done in our flow without having to hover over every bit of dynamic content from a compose action to see which compose it’s referencing.

So… there’s a little tip my community friend and colleague, Pieter Veenstra, taught me.

If we create a JSON object in our compose action and make what we first intended to put in that action as a value against a field, then we can query our object in a further place in our flow and the dynamic content will show the field name (or as much as it can fit in), which can help to give a preview of what that piece of dynamic content is holding without having to hover and wait for a tooltip to appear!

In your compose action, create a JSON object using {}. Inside those curly brackets define column names inside “” followed by : and their value. If the value is a string make sure you put it inside “”.

{ “MyColumn” : “MyOutput” }

Now in my future input which could be another compose or an action using a data connector, I’m going to use this expression to reference the example above.

outputs('Compose')?['MyColumn']

Now if we look at the dynamic content after refreshing our flow, you can see the column name there. This just helps to identify what is being held in our compose.

Now if we look at a flow run to see that the outputs are as we’re expecting here… you can see everything is working in the same way as if we just used a compose with the value inside it.

I hope this post helped you to understand how the compose action can be used in Power Automate! If you need any more help with understanding this, let me know.

Written by
Lewis Baybutt
Microsoft Business Applications MVP • Power Platform Consultant • Blogger • Community Contributor • #CommunityRocks • #SharingIsCaring
Comments
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to LewisDoesDev.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.