How to Initialize Object Variable in Power Automate

This flow tutorial will discuss how to initialize an object variable in Power Automate with an example.

Object Variable in Power Automate

In Power Automate, we can use different variable datatypes, one of which 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 key and value pair parameters.

{"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.
  • We will achieve this by creating an object variable type and then dynamically passing the content values using Power Automate.

How to Initialize Object Variables 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
  • 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
  • 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 in JSON format.
{
  "Sales Percent Value": "38.34",
  "Profit Percent Value": "60"
}
Initialize Object Variable in a Power Automate flow example

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

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
  • Then Test -> Save and run the Power Automate flow and select Run Flow automatically.
  • Once the flow has run successfully, 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
  • 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

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

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
  • 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
  • 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. Otherwise, Save and Test the Power Automate flow.
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
  • The screenshot below shows that the compose action output section displays the data value as expected from the SharePoint list.
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
  • The Screenshot below displays the expected result value in the compose action output section.
Example of Initialize Variable Object in Power Automate flow

This is another example of initializing the variable object type in the Power Automate flow.

This Power Automate tutorial shows how to initialize an object variable in Power Automate with different examples.

You may also like: