In this article, we will learn about variables, data types, creating variables, and how to perform operations and actions on them.
In previous chapters, we were sending one email for every product. We can send a list of products in one email with the help of variables. Variables are temporary storage inside Microsoft Power Automate flow where we can have a storage of data in which we can keep the content, numbers, strings, etc.
Data types of variables
Power Automate provides data types like Boolean, Integer, Float, String, Object, and Array.
- Boolean : In this data type the values can be True or False.
- Integer : It accepts a numeric value which should be a whole number. (eg: 4,2,8)
- Float : It accepts a numeric value that can be decimal. (eg: 123.5, 2.67)
- String : It accepts text input values. (eg: Hello, Microsoft)
- Array : It is used to input a list of objects which can be a number or string that have the same data type.
- Before we use variables we need to initialize them to define storage and memory to variables.
- Let's go to our Microsoft Power Automate.
- Click on Create from the left-hand side panel. Select Instant cloud flow.
- Give a name to the flow and select Manually trigger a flow. Click on Create.
- Click on the New step to add Variables.
- We need to create a variable. Select Initialize variable from actions.
- Enter Name for your variable. Select the data type of your variable.
- Assign the Value to the variable and click on the New step.
- Select Compose (Data Operation) from actions. With Compose action, we could only get the result from the value input, but we can't change the Input, which means there is no way to modify the original input of the same compose.
- Add Input as My Age variable from Add dynamic content. Click Save.
- Now, Test and Run Flow by Manually triggering it.
- After running the flow. We can the Output in Compose.
Performing Operations On Variables
- We can perform operations like Set, Increment/Decrement, and Append on variables.
- Click on the arrow between Initialize variable and Compose. Click on Add an action.
- Select Set variable from actions.
- Select the previous variable My Age and add Value to it.
- Test and Run Flow. Now click on Compose. Now the variable value will be set to a new value.
- Now, to increment the variable click on the arrow between Set variable and Compose. Click on Add an action.
- Select Increment variable.
- Select the variable Name and add Value. This will only work for variables that are of numeric data type.
- Test and Run Flow. Now click on Compose. Now the variable value will be incremented by 4. Similarly, you can do it for Decrement operation.
- To use the Append operation create a new variable of type String.
- Select Append to a string variable.
- Select the variable Name and add Value.
- Add Compose from actions. Add My Name variable from Add dynamic content. Click on Save.
- Test and Run Flow. Click on Compose. The new string is appended to the previous string variable.
Appending To An Array
- Initialize the variable with data type as Array. Enter values in Array format enclosed in square brackets and separated by commas. Go to New step.
- Select Append to array variable from actions.
- Select the variable name and add value. Click on the New step.
- Select Compose from actions. Select the variable name from dynamic content and Save.
- Test and Run Flow. You can see the output where the new string is appended to our array.