How to Initialize Object Variable in Power Automate

In this flow tutorial, we will discuss, how to initialize object variable in power automate with an example.

Also, you can read: How to Initialize Integer Variable in Power Automate

What is Initialize Object Variable in Power Automate

In Power Automate, we can use different variable datatypes and one of them is the Object data type.

When we initialize a variable with an object data type, it accepts the values in JSON format. For example, JSON format consists of two parameters called key and value pair.

{"name":"John", "age":30}

Where,

  • Key = name, age
  • Values = John,30

In the following example, we will see how to initialize an object variable in Power Automate flow.

Example-1

  • Recently, I got a requirement to send an email only to the selected users to notify the total sales and profit percentage values.
  • And we will achieve this by creating an object variable type and then we will dynamically pass the content values using Power Automate.

How to Initialize Object Variable in Power Automate

  • Create an instant cloud flow -> Add the flow name (Power Automate initialize variable object) -> Select the Manually trigger a flow -> Click on the Create option.
power automate initialize variable object
power automation initialize the variable object
  • Expand the trigger action, select +Add an input, and then choose the Input type as Number.
  • Enter the Input number field Name, here I have added two input number fields called Sales %Value and Profit % Value as highlighted below:
Initialize Object Variable in a Power Automate flow
Initialize Object Variable in a Power Automate flow
  • And then we will add the action “Initialize variable“ action. Later, we will add the Variable name and choose the variable type as an Object.
  • Add the dynamic content values for the added sales and profits values in a JSON format.
{
  "Sales Percent Value": "38.34",
  "Profit Percent Value": "60"
}
Initialize Object Variable in a Power Automate flow example
Initialize Object Variable in a Power Automate flow example

Now we will add an compose action to check the output of the initialized variable object.

Initialize Object Variable type in a Power Automate flow example
Initialize Object Variable type in a Power Automate flow example
  • To send an email, we will select the send an email action from the list of actions and then add the specific email address to the “To” section.
  • Add the email “Subject“, here I have added the subject Sales and Profit Value as my email subject.
  • In the Body section, we will add the message you want to send to the selected users.
Initialize Object Variable type in a Power Automate flow
Initialize Object Variable type in a Power Automate flow
  • And then Test -> Save and run the Power Automate flow and select Run Flow automatically.
  • Once the flow has run successfully, we can see it notifies the mentioned recipient. In the output section, we can see the click-to-download option, it redirects to the output values.
Initialize Object type Variable in a Power Automate flow
Initialize Object type Variable in a Power Automate flow
  • And then we will receive the below email to the mentioned user with the message added in the send email action.
Initialize Object type Variable in a Power Automate
Initialize Object type Variable in a Power Automate

This is how to initialize the variable object in the Power Automate flow.

Check out: How to Check If a Date is Blank in Power Automate?

Example:2

Here we will see how to initialize the variable object type in the Power Automate flow.

  • Now we will create a Power Automated flow with the trigger When an item is created or modified as below:
How to Initialize Variable Object in the Power Automate
How to Initialize Variable Object in the Power Automate
  • Then we will choose the action as Initialize variable action from the list of actions. Later, we will enter the Variable name (VarObject) and choose the Type as an Object.
  • Add the dynamic content values from the SharePoint list in a JSON format as highlighted below:
Initialize Variable Object type in Power Automate
Initialize Variable Object type in Power Automate
  • Now select the +new step to add the compose action to see the output value from the initialized variable.
Initialize Variable Object type in the Power Automate
Initialize Variable Object type in the Power Automate
  • Select the Flow checker, and fix if the error occurs. Else, Save and Test the Power Automate flow.
Test Power Automate
Test Power Automate
  • Here we will select and modify the below highlighted SharePoint list item so that the power automate flow will trigger.
How to Initialize Variable Object in the Power Automate flow
How to Initialize Variable Object in the Power Automate flow
  • In the below screenshot, you can see the compose action output section displays the data value as expected from the SharePoint list.
How to Initialize Variable Object in Power Automate flow
How to Initialize Variable Object in Power Automate flow
  • In the same way, we will modify the different SharePoint list items as highlighted below:
Initialize Variable Object type in Power Automate flow
Initialize Variable Object type in Power Automate flow
  • The Screenshot below displays the expected result value in the compose action output section.
Example of Initialize Variable Object in Power Automate flow
Example of Initialize Variable Object in Power Automate flow

This is another example to initialize the variable object type in the Power Automate flow.

Additionally, you may like some more SharePoint and Power Automate tutorials:

In this Power Automate tutorial, we have learned what is Power Automate variable object type and how to initialize the variable object in Power Automate with different examples.