In this Power Automate tutorial, we will discuss Power Automate compose action. And also we will discuss the below points:
- Power automate compose
- Power automate compose vs variable
- Power automate compose JSON
- Power automate compose array
- Power automate compose expression
- Power automate compose array to string
- Power automate compose append string
- Power automate compose addition
- Power automate compose concat
- Power automate compose first item in array
- Power automate compose formatdatetime
- Power automate compose length
- Power automate compose today’s date
- Power automate compose string to integer
- Power automate compose union
Power Automate compose action
The compose is a data operation action in Power Automate or Microsoft Flow that will create an arbitrary object from the inputs.
Power Automate compose vs variable
Here we will discuss the difference between the compose and variable in Power Automate.
Variable | Compose |
---|---|
Variables hold different types of data types like string, boolean array, etc, to validate what we give in terms of our data. If the data doesn’t match the data types it will give an error. | Compose action is typeless, which means it is very flexible, we can provide any type of data(we can give XML, JSON, etc) as an input. |
Variables can be set many times, which means we can set it, reset it at any point of our flow, as per our requirement. | Compose only set once, which means compose doesn’t have the update function |
It can be grouped together under the variable heading, which means when we access the variable from the dynamic content. It was very clearly visible in the dynamic content because we can see the name of a variable, and also make it easy to identify what the variable is in dynamic content and what variable I want to use. | Compose are not grouped, which means we give some data as input and it will return some data as output. So in dynamic content, we can only identify the output as the name of the compose action itself. |
Variables need to be initialized, while initializing we need to give name, type, and initial value. When we initialize a variable, the initialize variable action can’t declare within the scope, and it is generally declared in the top level of the flow. | Compose can be created anywhere in the flow, it can be created inside the scope or at any point throughout the flow |
Read How to call a flow from another flow in Power Automate
Power Automate compose JSON
Here we will see an example of Power Automate compose JSON.
Now we will create a flow that will retrieve data from the SharePoint list and build a JSON.
Let’s see an example of Power Automate compose JSON.
I have a SharePoint list called Leaves Request, so from this list, we will retrieve items and build a JSON using compose action.
In Power Automate, select the Manually triggered flow, then click on the Next step.
Now we will retrieve items from the SharePoint list, so click on the Next step and select Get items action, then provide the site address, list name.
Next, initialize variable as an array, so click on the Next step and select Initialize variable action, set the name as itemsArray, type set to Array, and value is empty.
Now add an Apply to each action, the provide the value from dynamic content. Then add an action and select compose action, then in input provide the value like below.
Next, click on the Next step and select Append to array variable action, then select the variable name and in value select the output from the dynamic content.
After the Apply to each action, click on the Next step and select Compose action. Then in input write the below formula.
Now click on Save and run the flow, you can see the JSON in the compose output.
This is an example of Power Automate compose JSON.
Read Power Automate Set Variable
Power Automate compose array
Here we will see how to add a property to an array using Compose action in Power Automate.
In Power Automate, select the Manually triggered flow, then click on the Next step.
Now we will initialize the array variable, so click on the Next step and select initialize variable action. Then provide the variable name, type as an array, and in value write the below array:
[
{
"FullName": "Christen Ronald",
"Age":30,
"Address":"Arizona"
},
{
"FullName": "Alex Ronald",
"Age":32,
"Address":"Alaska"
}
]
In the Next step, select Apply to each action and select the variable as an output from the dynamic content.
Then we will add a property to each object in an array, so click on add action and select Compose action. Then in input add the below expression:
addProperty(item(),'Department','HR')
Now click on Save and run the flow, you can see the property added to each object in an array.
This is an example of Power Automate compose array.
Read Power Automate wait timer – How to use
Power automate compose expression
Here we will see how to use the expression in Compose action in Power automate.
In compose we will write an expression, which will replace the string ‘Automate’ with ‘Apps’.
In Power Automate, select the Manually triggered flow, then click on the Next step.
Select the Initialize variable action, then provide the variable name, type as a string, and in value like below.
Now add a compose action to replace automate with apps, so click on the Next step and select Compose action. Then in Input write the below expression.
replace(variables('varString'),'Automate','Apps')
Now, click on Save and run the Flow manually, you can see the output of the compose action.
This is an example of Power Automate compose expression.
Read Power Automate update SharePoint list increment integer field
Power Automate compose array to string
Here we will see how to convert array to string using Power Automate.
We will create a flow that will convert the below array to string using Power Automate.
[
{
"DisplayName": "Bob Jones",
"Email": "[email protected]",
"JobTitle": "Singer"
},
{
"DisplayName": "Jane Doe",
"Email": "j[email protected]",
"JobTitle": "Lighthouse Painter"
}
]
After converting the array we will get the below string:
Jane Doe – [email protected] – Lighthouse Painter
Bob Jones – [email protected] – Singer
Let’s see how to create a flow to convert the array to string using Power Automate.
In Power Automate, select the Manually triggered Flow, then click on the Next step.
Select Initialize variable action, then provide the variable name, type as Array, and in value add the above array.
To store the output string, click on the Next step and select Initialize variable action, then provide the variable name, and type as a string.
Now to convert the array to string, click on the Next step, add Apply to each action. and select vararray from the dynamic content as an output.
Then click on Add an action and select Compose action, then in Inputs write the below expression.
concat(item()?['DisplayName'],' - ',item()?['Email'],' - ',item()?['JobTitle'])
Then click on Add an action, and select Compose action, then in inputs add the output from the dynamic content, then go to next step and select FinalString from the dynamic content.
Now we will set the variable, so click on the Next step and select Set variable action, then provide the variable name and in value, select the outputs from the dynamic content.
Now click on the Next step, and select Compose action, then in Inputs select the FinalString from the dynamic content.
Now click on Save and run the flow manually and you can see the output in the compose action.
This is an example of Power Automate compose array to string.
Read How to move emails to folder after 30 days using Power Automate
Power Automate compose append string
Here we will see an example of append string in Power Automate compose action.
So here we want multiple user Emails from the SharePoint person field to send a Notification, so we need to Append to the string variable.
For this example I will use the Project management list, there is a column Assigned to which is a person field.
In Power Automate, select the trigger ‘When an item is created’- SharePoint list. Then provide the site address and list name.
Next, Initialize a variable as String, so click on the Next step and select Initialize variable action, then provide the variable name and type as a string.
Now we will Append each email to the string variable, so click on the Next step and select Append to a string variable, then select the variable name and in value select the person field, that will automatically add Apply to each action.
Next, add a compose action, then in input select the varuserEmail from the dynamic content.
Now click on Save and to run the flow create an item in the SharePoint list, and you can see multiple emails are separated with ‘;’
This is an example of power automate compose append array.
Read Power Automate list rows present in a table filter query
Power Automate compose addition
Here we will see how to add two numbers or integers in the compose action.
In Power Automate, select the Manually triggered flow, then click on the Next step.
Now we will initialize two integer variables, so click on the Next step and Initialize variable action then provide the variable name, type as integer and provide the value.
Next we will add the two integer variable, so click on the Next step and select compose action, then in input add the below expression:
add(variables('num 1'),variables('num2'))
Now click on Save and run the flow manually and you can the addition of two number.
This is an example of Power Automate compose addition.
Check out, Power Automate Get Events into Excel
Power Automate compose concat
Here we will see how to use concat function in Power Automate compose action.
In Power Automate, select the Manually triggered flow, then click on the Next step.
Now we will assign a string i.e. Power, to a variable, so select Initialize variable action, then provide the variable name, type as String, and in value provide Power Automate.
In this step we will concat the above string with another string i.e. Automate, so click on the Next step and select compose action. Then in input provide the below expression.
concat(variables('varString'),'Automate')
Now click on Save and run the Flow manually, and you can see both the string concatenated.
This is an example of Power Automate compose concat.
Read Microsoft flow send email based on create date
Power Automate compose first item in array
Here we will see how to get the first item value in array using Power Automate.
So here we will use the below array and we will retrive the DisplayName i.e. Boby jones from an array.
[
{
"DisplayName": "Bob Jones",
"Email": "[email protected]",
"JobTitle": "Singer"
},
{
"DisplayName": "Jane Doe",
"Email": "j[email protected]",
"JobTitle": "Lighthouse Painter"
}
]
In Power Automate, select the Manually triggered Flow, then click on the Next step.
Select Initialize variable action, then provide the variable name, type as array, and in value provide the above array.
Now we will get the first item value, so click on the Next step and select compose action. Then in input provide the expression:
variables('varArray')?[0]?['DisplayName']
Now click on Save and run the Flow Manually, you can see the result in the compose output.
This is an example of Power Automate compose first item in array.
Read Power Automate or Microsoft Flow check day of week
Power Automate compose formatdatetime
Here we will see how to use formatdatetime function in Compose action using Power Automate.
In Power Automate select the Manually triggered flow, then click on the Next step.
In this step, we will initialize variable as string, so select Initialize variable action, then provide the variable name, type as string and in value provide a sample date.
Now we will format the date with ‘yyyy-MM-dd’, so click on the Next step and select compose action. Then in input add the below expression:
formatDateTime(variables('Date'),'yyyy-MM-dd')
Now click on Save and run the Flow manually, you can see the result in the compose output.
This is an example of Power Automate compose formatdatetime.
Read Power Automate Desktop Flow – How to start
Power Automate compose length
Here we will see how to use length function in Compose action in Power Automate.
In Power Automate, select the Manually triggered flow, then click on the next step.
Then select the Initialize variable, provide the variable name, type as string and in value provide the sample string.
Next, add a Compose action, then in Input provide the below expression, that will measure the length of the above string.
length(variables('varString'))
Now click on Save and run the flow Manually, and you can see the length of the string.
This is an example of Power Automate compose length.
Read Power Automate SharePoint Get Items Filter Query
Power Automate compose today’s date
Here we will see how to get today’s date in Compose action in Power Automate.
In Power Automate, select the Manually triggered flow, then click on the Next step.
Now we will get the today’s date, so select Compose action, then in Input provide the below expression:
formatDateTime(utcNow(),'yyyy-MM-dd')
Now click on Save and run the flow manually, you can see the date in the compose action.
This is an example of Power Automate compose today’s date.
Read Power Automate send email to SharePoint group
Power Automate compose string to integer
Here we will see how to convert string to integer Power Automate Compose action.
In Power Automate select the Manually triggered Flow, then click on the Next step.
Now select initialize a variable action, then provide the variable name, type as string and in value provide like below.
Next, add a Compose action, then in Input write the below expression to convert the above string into an integer.
int(variables('Text'))
Now click on Save and run the Flow manually, you can see the result in the output of the Compose action.
This is an example of Power Automate compose string to integer
Read Power Automate remove characters from a string
Power Automate compose union
Here we will see how to use union function in Power Automate Compose action.
In this example, we will take two arrays, and we will find the union of two arrays.
In Power Automate select the Manually triggered flow, then click on the Next step.
Select the Initialize variable action, then provide the variable name, type as Array, and provide the value like below:
Next, initialize an array variable, so click on the Next step and select Initialize variable action. Then provide the variable name, type as an array, and in value add the below array.
Now we will find the union between two array, so click on the Next step and select Compose action. Then in Input write the below expression:
union(variables('varArray1'),variables('varArray2'))
Now click on Save and run the Flow Manually, you can see the union of two arrays in the output of the compose action.
This is an example of the Power Automate compose union.
Related Power Automate tutorials:
- Power Automate Array Variable
- Power Automate send email based on form response
- How to convert word to pdf using Power Automate
- Power automate split string into an array with examples
- Power Automate Rename File
- Power Automate String Functions + 10 Examples
- Power Apps Navigate Function + 16 Examples
In this Power Automate tutorial, we learned about Power Automate Compose action. And also we will discuss the below points:
- Power automate compose
- Power automate compose vs variable
- Power automate compose JSON
- Power automate compose array
- Power automate compose expression
- Power automate compose array to string
- Power automate compose append string
- Power automate compose addition
- Power automate compose concat
- Power automate compose first item in array
- Power automate compose formatdatetime
- Power automate compose length
- Power automate compose today’s date
- Power automate compose string to integer
- Power automate compose union
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.
Great post! How can I use the output of a “Compose” action (i.e. an array of names) to populate fields in a “Create Item” action? Thank you!
Thank you!!! Finally, a really helpful and detailed post with information I’ve not been able to find in the documentation. Your table of differences between variables and compose cleared up something for me that I’ve been struggling with for _years_. Invaluable! This information should be added to Microsoft’s official documentation!