The most common approach to keep any configuration data into CRM is to keep them into a custom entity with a key value pair. This approach puts one extra overhead to move the configuration data into Production either using DataMigrationTool or by writing custom code to make it part of the DevOps Pipeline.
Microsoft D365 in the latest update has come up with a solution to make the configuration data movement much easier than it could have been earlier.
MSFT has introduced Environment variables that can be migrated along with the solution.
Here in this article we have all the steps from creating Environment variables and using it in code. You can also get the best solutions from Microsoft CRM Development team here.
Creating Environment Variable:
Login to https://make.powerapps.com
Go to Solutions and create a new solution.
Create a new Environment variable and name it “Test”.
Mentioned default value will be the value that will be migrated along with the Solution.
Note: We can have another value as “Current Value” to override the Default value in any environment. If we have different values in Production and Development for the Environment Variable, current value can be used to keep separate values in Development.
Managing the Environment Variables into CRM app:
Any Environment variable added through the PowerAdmin into the solution is also available into CRM application as all the values are saved in following 2 entities:
1. Environment Variable Definition:
Default values are available in this entity along with the Key name.
2. Environment Variable Values:
Any environment specific value can be added directly by adding a record of this entity. Relationship between Environment Variable Definition & Environment Variable Values is enforced as 1:1. We can have only one record for any Key-Value pair.
Using Environment Variables into Code
Environment variables can be fetched the same way we fetch values from any entity.
Query to fetch the Default value.
Query to fetch the Current Value specific to the environment
Environment variables are good to use if we want the configuration values to migrate along with Solution but at the same time, these features still need more enhancements to incorporate.
- Caching : to avoid any service call to fetch Environment variables run time.
- There are multiple issues found while migrating Environment variables and also while unpacking/packing(using Solution Packager) a solution comprising an Environment variable.
Above mentioned points are very important for full fledged use of Environment Variable. To get more tutorials, stay tuned with our experts here.