As applications grow in complexity, managing and maintaining Dynamics 365 environments becomes increasingly challenging. With multiple teams working on different aspects of the system, ensuring the correct values are used in the appropriate places can be a daunting task. To address this challenge, the utilization of environment variables proves beneficial.
Environment variables are a powerful feature within Dynamics 365 that allows for the definition of values once, which can then be used across multiple areas within the system. By leveraging environment variables, organizations can maintain consistency, mitigate the risk of errors, and facilitate future updates to values with ease.
Each environment variable comprises two essential components: the default value and the current value. The default value remains constant across all environments and can be seamlessly transferred from one environment to another. On the other hand, the current value is specific to each individual environment and can be added or modified as needed.
Now that we have an entity to store the configuration, the next step is to retrieve the stored config value in JavaScript. Fortunately, there are several approaches to accomplish this task without resorting to multiple retrieve multiple calls. By using a built-in function and the “RetrieveEnvironmentVariableValue” method, a single SDK request can retrieve the desired value from the environment variables. This streamlined approach simplifies the process and eliminates unnecessary complexity.
In summary, leveraging environment variables in Dynamics 365 enables organizations to effectively manage their growing applications. By centralizing values and utilizing the appropriate retrieval methods, businesses can maintain consistency, reduce errors, and enhance their overall system management.
var Sdk = window.Sdk || {};
Sdk.RetrieveEnvironmentVariableValueRequest = function (definitionSchemaName) {
this.DefinitionSchemaName = definitionSchemaName;
};
Sdk.RetrieveEnvironmentVariableValueRequest.prototype.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {
"DefinitionSchemaName": {
"typeName": "Edm.String",
"structuralProperty": 1
}
},
operationType: 1,
operationName: "RetrieveEnvironmentVariableValue"
};
};
var retrieveEnvironmentVariableValueRequest = new Sdk.RetrieveEnvironmentVariableValueRequest({EnvironmentVariableSchemaName});
Xrm.WebApi.online.execute(retrieveEnvironmentVariableValueRequest).then(
function success(result) {
if (result.ok) {
result.json().then(
function (responseBody) {
console.log(responseBody.Value);
});
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
});

Reblogged this on Nishant Rana's Weblog.
LikeLike