Tue, 10/13/2020 - 14:38 By Lorenz Prandini
environment variables Dynamics 365

Overview

Today we have a look at solution component Environment Variable Definition and Environment Variable Values in Dynamics 365. We took this blog from November 2019 that introduced us to this new solution components and put it to the test in regards of deployment. 

Environment Variable Definitions and Values are used to handle environment specific configurations - for example webhooks that differ from dev, test or production. 

Solution components

Environment Variable Definitions can be created inside the Power App studio of your environment. They can be part of a solution and therefore fall into the category of a solution component.

solution component

An Environment Variable Definition can have a Name, Default Value, Data Type and a Current Value. There should be only one current value - we call this Environment Variable Value. Environment Variable Definition and Environment Variable Value share a 1:1 relationship.

solution component edit

Environment Variable Value can be updated, deleted or excluded from the solution:

environment variable value edit

When adding an existing Environment Variable Definition you can choose if you want to add the Environment Variable Value too:

add component environment variable definition

Environment Variable Definition and Environment Variable Value currently can only be used by standard CDS API calls. This makes it more difficult to know how to handle the definitions and values. 

Deployment of Environment Variable Definitions

For our scenario we will work with two environments: DEV and TEST. The solution will be exported as managed from DEV and imported in TEST.

Solution A: no default value and no Environment Variable Value

When importing a Solution A you will get asked to populate the current value of the Environment Variable Value as there is no default.

solution import with no default or current value

The default value will still be empty but a Environment Variable Value record will be created. We can see this using the Advanced Find:

C:\Diverses\chronicles\environment variable\advanced find environment variable value.png

This Environment Variable Definition can be edited or deleted but there can always be only one value per definition.

Solution B: default value without Environment Variable Values

When importing Solution B you will have no dialog to set the current value of the Environment Variable Definition. There will be no Environment Variable Values. As there are no specific action related to Environment Variable in the CDS we can only query the records for the entity Environment Variable Definition or Environment Variable Value.

Solution C: no default value with Environment Variable Values

When importing Solution C you will see a dialog asking for the current value of the Environment Variable Definition. Because we included the DEV Environment Variable Value it auto-suggests the value:

C:\Diverses\chronicles\environment variable\solution import with no default but current value.png

We realized that on importing the Solution C the GUID of the Environment Variable Value stays the same. The GUID can be found as usual in the URL of the Environment Variable Value record or in the JSON created in the solution zip:

solution components folder

Even though the solution is managed you are allowed to overwrite the values. If you import the solution again the target Environment Variable Value will NOT be updated. 

This means that in CDS queries you could create the fixed GUID so you can save yourself a multiple retrieve.

Additionally the record created during the import of the managed solution cannot be deleted on the target environment as it counts as a managed component.

C:\Diverses\chronicles\environment variable\deleted manage values.png

Summary

In general as there are only the common CDS actions we do not recommend mixing default value and Environment Variable Value. Instead you should create your logic to use Environment Variable Values with fixed GUID that is only provided in Solution C. This is very important as the Environment Variable Values have no alternate key. Additionally, the having the Environment Variable Value initially created via solution import as in Solution C you are not able to delete or replace the record. That way you make sure your logic prevails. 

In your queries you can use the deployed GUID like this:

https://{your-url}.crm4.dynamics.com/api/data/v9.1/environmentvariablevalues(ea152a68-470d-eb11-a813-000d3a49c2d7)

Add new comment

Image CAPTCHA
Enter the characters shown in the image.