Initialize Variable in Power Automate

Do you want to learn how to initialize variables in Power Automate? In this Power Automate tutorial, I will explain to you how to initialize variable in Power Automate.

Also, we will discuss the types of variables we can initialize in Power Automate, and how we can use them.

Here we will cover the below topics:

  • Power Automate initialize variable
    • Power Automate initialize variable types
  • How to use initialize variable in Power Automate
    • Power Automate initialize variable string
    • Power Automate initialize variable array
    • Power Automate initialize boolean variable
    • Power Automate object variable
  • Power Automate initialize variable date

Power Automate initialize variable

A variable in Power Automate acts as a temporary data container. When you use variables, an important first step is to set them up, which is called “initializing.” Initializing a variable means giving it a starting value and specifying what kind of data it will hold. Once initialization is done, you can change the value of the variable whenever required as you proceed with your flow.

The initialize variable action accepts 3 parameters:

  • Name: Provide the variable name
  • Type: It is the type of the variable
  • Value: Initial value assigned to the variable
initialize variable power automate

Power Automate initialize variable types

The types of variables we can initialize in Power Automate are:

  • String- It is used as text input i.e. hello, SharePoint, etc.
  • Boolean- The value can be either true or false.
  • Float- It accepts the numeric data type that has decimal i.e. 45.23, 78.4553, etc.
  • Number– It accepts only numerical data type i.e. 60, 25, etc
  • Object- It contains the pair of properties and value that are in JSON format.
  • Array- Initialize a list of items or objects which must be a similar datatype.
power automate initialize variable

Initialize variable in Power Automate

Here we will see how to use the initialize variable action in Power Automate with examples.

See also  The DateTime String must match ISO 8601 format error in Power Automate

Example 1: Power Automate initialize variable string

We will first initialize a string variable and then we will use this variable in Power Automate. Let’s start with initializing a variable.

1. In Power Automate Cloud, create an instant cloud flow, that will trigger manually.

power automate initialize variable types

2. Now click on the +New step to initialize the string variable. For this, click on the Initialize variable action. Provide the information below

  • Name– Here, we have to give a name to our variable.
  • Type– Here select the type as String
  • Value– Provide the value like below
power automate initialize variable string

3. To use the variable in the flow, we can add the variable to any action available in Power Automate. For this, click on +New step -> select Compose action. Then provide the below information:

  • Inputs: Select the variable from dynamic content.
how to use initialize variable in power automate

4. Now save the flow and run the flow manually, you can see we have used the initialize variable action in the Power Automate flow.

variables in power automate

Example 2: Power Automate initialize variable array

Now, we will see how to initialize the variable with the Array data type in Power Automate.

Let’s say we have an array i.e. [Chicago, New York, Los Angeles, Texas, California]. We want to show this array in Power Automate.

1. In Power Automate Cloud, create an instant cloud flow, that will trigger manually.

power automate initialize variable types

2. Now click on the +New step to initialize the array variable. For this, click on the Initialize variable action. Provide the information below

  • Name– Here, we have to give a name to our variable.
  • Type– Here select the type as Array
  • Value– Provide the value like below
power automate initialize variable array

3. To use the variable in the flow, we can add the variable to any action available in Power Automate. For this, click on +New step -> select Compose action. Then provide the below information:

  • Inputs: Select the variable from dynamic content.
initialize variable array power automate

4. Now save the flow and run the flow manually, you can see we have used the initialize variable action in the Power Automate flow.

initialize variable array in power automate

Example 3: Power Automate initialize boolean variable

Here, we will see how to initialize the boolean variable and how to use the initialize variable in Power Automate.

See also  How to Convert String to GUID in Power Automate?

Let’s say we will initialize a variable IsCompleted and we will set it to true and in compose action we will use this variable in Power Automate.

1. In Power Automate Cloud, create an instant cloud flow, that will trigger manually.

power automate initialize variable types

2. Now click on the +New step to initialize the boolean variable. For this, click on the Initialize variable action. Provide the information below

  • Name– Here, we have to give a name to our variable.
  • Type– Here select the type as Boolean
  • Value– Provide the value like below
power automate initialize boolean variable

3. To use the variable in the flow, we can add the variable to any action available in Power Automate. For this, click on +New step -> select Compose action. Then provide the below information:

  • Inputs: Select the variable from dynamic content.
power automate initialize variable boolean

4. Now save the flow and run the flow manually, you can see we have used the initialize variable action in the Power Automate flow.

power automate boolean variable

Example 4: Power Automate object variable

Here we will see how we can initialize the object variable and how we can use this variable in Power Automate

1. In Power Automate Cloud, create an instant cloud flow, that will trigger manually.

power automate initialize variable types

2. Now click on the +New step to initialize the string variable. For this, click on the Initialize variable action. Provide the information below

  • Name– Here we have to give a name to our variable.
  • Type– Here select the type as String
  • Value– Provide the value like below
power automate object variable

3. Now we will parse the object to fetch the name and age, for this click on the +New step and select the Parse json action.

Provide the below information:

  • Content: Select the variable from dynamic content
  • Schema: To add schema, click on Generate schema and provide the json code.
power automate initialize variable object

4. Now click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the value line below:
Name: @{body('Parse_JSON')?['Name']}
Age:@{body('Parse_JSON')?['Age']}
power automate initialize object

5. Now save the flow and run the flow manually, you can see the output of the initialized object variable.

power automate create object variable

This is how to initialize variables in Power Automate and use the initialized variable in Power Automate flow.

See also  Power Automate Trigger Conditions

Power Automate initialize variable date

Here, we will see how to initialize a date variable in Power Automate.

In Power Automate, there is no “date” type to initialize the variable in Power Automate. So we will initialize a string variable and we will assign the date. Also, I will add 30 days to date while initializing the variable in Power Automate.

1. To implement this, we will create an Instant cloud flow, that will trigger manually. Then, we will add input as a Date.

Power Automate Initialize Variable date

2. Next, we will initialize a variable action and then provide the below information:

  • Name: Provide the variable name
  • Type: select type as String
  • Value: Provide the below expression
addDays(triggerBody()['date'],30)
Initialize Variable date Power Automate

Now we will test the flow, it will ask to insert the date. For example, we will insert today’s date i.e. 10/29/2021

Power Automate Initialize Variable Date type

Once the flow runs successfully you can see the output(i.e. 2021-10-29 + 30 = 2021-11-28).

Initialize Variable date Power Automate

This is how to initialize the date variable in Power Automate.

Conclusion

In this Power Automate tutorial, we saw about initialize variable in Power Automate. Also, we cover the below topics:

  • Power Automate initialize variable types
  • How to use initialize variable in Power Automate
    • Power Automate initialize variable string
    • Power Automate initialize variable array
    • Power Automate initialize boolean variable
    • Power Automate object variable
  • Power Automate initialize variable date

You may also like:

>