How to set up, deploy and use JSON environment variables in Power Automate
Queues, teams and users can have different GUIDs in every environment. With a single environment variable, your flows look up the right GUID in each environment, without hardcoding and without copying records between environments.
A flow that sends an email from a queue needs the queue’s GUID. The problem is that the same queue has one GUID in DEV, another in TEST and a third in PROD.
If you hardcode the GUID, the flow only works in one environment, and it’s inflexible to change. Maybe you want the queue in the flow to point to a different queue, for example if you only have a few active queues in DEV. If you copy records between environments to get matching GUIDs, you end up with a fragile setup that’s easy to forget and hard to maintain.
There’s a better and simpler way: let an environment variable keep track of the GUIDs for each environment.
Examples of what you can use it for
- Send email from the right queue in every environment from Power Automate, whatever GUID the queue has in each environment.
- Other tables: the same pattern works for teams (
team), users (systemuser), contacts (contact) and anything else you need to fill in dynamically in flows that work with records. - Beyond flows: environment variables can also be read from, for example, JavaScript and canvas apps.
An example of how to set it up for queues
1. Create a JSON object with queue names and GUIDs
The structure is simple: the key is the queue name, the value is the GUID. Here are the DEV, TEST and PROD values for four queues per environment:
2. Create the environment variable
Create the environment variable in a solution in DEV:
- Display name:
Queue GUIDs - Name (schema name):
prefix_queueguids(new_queueguidsin this example) - Data Type:
JSON - Default Value: the JSON from step 1 (PROD)
We use the PROD values here because we want the first deployment to set them in PROD, not someone doing it by hand. Later we replace them with the DEV values.
While you’re developing, put the DEV values in the Current Value in DEV, so the flows work there.
3. Deploy to TEST
After deploying to TEST, we set the Current Value for that environment.
4. Deploy to PROD
After deploying to PROD, we set the Current Value for PROD. It will be the same as the Default Value. Then we change the Default Value in DEV to the DEV values.
That way every environment gets the right values, and we make sure the first go-live gets the right values straight away.
5. Later changes
The next time something needs to change, you update the Current Value manually in each environment. It’s important to keep the values up to date in every environment.
This approach works with both unmanaged and managed solutions. In a managed solution, the Default Value can’t be changed in the target environment, but you don’t need to: the Default Value is only changed in DEV, and the Current Value can always be set manually. What suits you best depends on the deployment setup you use. Read more in Managed and unmanaged solutions, explained simply.
How to use the environment variable in a flow
The demo flow has a manual trigger with a “Queue Name” input and two Compose actions: one that gets the GUID for the queue you enter, and one that gets a fixed queue.
Get the GUID for the queue from the trigger:
parameters('Queue GUIDs (new_queueguids)')?[triggerBody()?['text']]
Get the GUID for a fixed queue:
parameters('Queue GUIDs (new_queueguids)')?['Customer Support']
How the expressions work:
- Power Automate references environment variables as
parameters('Display name (schema_name)'). - A JSON environment variable comes in as an object, so you can use
?['key']directly. You don’t needjson()or a Parse JSON action. ?makes the expression return null instead of failing if the key is missing. It also means a typo in the queue name fails silently, so check the spelling.textis the internal name of the first text input in a manual trigger. Further inputs are namedtext_1,text_2and so on.
When the flow runs with “Complaints” as input (one of the queues in the example), the first action gets the Complaints GUID, and the fixed lookup returns the Customer Support GUID:
Pitfalls and tips
- The Current Value in TEST and PROD isn’t optional. Once the Default Value in DEV has been changed to the DEV values, the DEV values travel with the next deployment as the Default Value. The Current Value is what keeps TEST and PROD on their own values.
- Turn the flow off and on again after changing a value directly in the environment. Otherwise the flow may keep using the old value.
- The flow must be solution-aware to use environment variables, and should be in the same solution as the environment variable so they’re deployed together.
Stop copying records between environments
With a single JSON environment variable, you avoid hardcoded GUIDs and copied records. Your flows find the right queue (or other record) in every environment, and PROD gets the right values from the first deployment.