Back to the blog

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.

Development5 min read

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:

JSON for DEV, TEST and PROD with different GUIDs for the same four queues
The same four queues, with different GUIDs in DEV, TEST and PROD.

2. Create the environment variable

Create the environment variable in a solution in DEV:

  • Display name: Queue GUIDs
  • Name (schema name): prefix_queueguids (new_queueguids in 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.

The New environment variable dialog with Data Type JSON and the PROD values in Default Value
A new environment variable with the PROD values in Default Value (4c1d8e3b-…).

While you’re developing, put the DEV values in the Current Value in DEV, so the flows work there.

Edit Queue GUIDs in DEV: Default Value starts with 4c1d8e3b, Current Value with 3f8a2c71
DEV: the PROD values in Default Value (4c1d8e3b-…), the DEV values in Current Value (3f8a2c71-…).

3. Deploy to TEST

After deploying to TEST, we set the Current Value for that environment.

Edit Queue GUIDs in TEST: Default Value starts with 4c1d8e3b, Current Value with 7b2e9d40
TEST after deployment: the Default Value is PROD (4c1d8e3b-…), the Current Value is TEST (7b2e9d40-…).

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.

The Display queueid flow with a manual trigger and two Compose actions
The demo flow in edit mode.

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 need json() 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.
  • text is the internal name of the first text input in a manual trigger. Further inputs are named text_1, text_2 and 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:

A successful flow run where both Compose actions show a GUID
The input "Complaints" returns e15c3a8d-…, and the fixed lookup returns Customer Support's 3f8a2c71-….

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.

  • Power Automate
  • Environment variables
  • ALM

Written in Norwegian. Translated to English with the help of AI.

More from the board

  • Translations in Dataverse done in under 30 seconds

    Translations have long taken far more time than they should. With CRM Toolbox for Dynamics 365 you do them right in the browser, and see straight away what's actually been translated.

    3 minWorking smarter

  • Managed and unmanaged solutions, explained simply

    What's the actual difference, why do we use unmanaged in development and managed everywhere else, and what's the deal with all the layers? Here's the whole picture, without the jargon.

    7 minPower Platform