Power Automate: Using Arrays as Environment Variables
Introduction
In Power Automate/Power Platform, environment variables within solutions are essential for managing and configuring flows across different environments. However, there is no direct way to declare an environment variable as an array. This blog post will cover how to use JSON to store arrays as environment variables, enabling you to manage complex data structures efficiently.
Available Environment Variable Types
Power Automate offers various types of environment variables you can select and configure:
- X2 Decimal number
- {} JSON
- Text
- Yes/No
- Data source
- Secret
For more information about the different types, refer to Power Platform Environment Variables.
Using JSON to Store Arrays
Fortunately, JSON can store data objects or arrays. By declaring the environment variable with the type JSON, arrays can be defined.
Step-by-Step Guide
- Declare the environment variable with type JSON and assign the default value:
{"Approvers": ["reshmee.auckloo@contoso.co.uk", "rauckloo@contoso.co.uk", "testuser@contoso.co.uk", "testuser2@contoso.co.uk", "testuser3@contoso.co.uk" ]}
- Add the
Parse JSON
action
Add the folloing schema:
{
"type": "object",
"properties": {
"Approvers": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Alternatively, you can click on Generate from Sample
and paste the JSON from step 1 to automatically generate the schema.
- Use the Parsed JSON
Refer to the parsed json within any action, in the example below, it is assigned the array to a variable.
body('Parse_JSON_-_Approvers_environment_variable')?['Approvers']