
In my private project (Key Box), I stored a JSON configuration in an Environment Variable. To retrieve its value, I had could use two queries. The first query to retrieve the GUID of the Environment Variable Definition and the second query to retrieve the Environment Variable Value. But there is a better way: the RetrieveEnvironmentVariableValue WebApi function.
Below is the async function I wrapped around it to make it easy reusable.
async function getEnvironmentVariableValue (schemaName) {
return Xrm.WebApi.online
.execute({
DefinitionSchemaName: schemaName,
getMetadata: function () {
return {
boundParameter: null,
parameterTypes: {
DefinitionSchemaName: {
typeName: "Edm.String",
structuralProperty: 1,
} ,
},
operationType: 1,
operationName: "RetrieveEnvironmentVariableValue",
};
},
})
.then(function success(response) {
if (response.ok) {
return response.json();
}
})
.then(function (responseBody) {
return responseBody["Value"];
})
.catch(function (error) {
console.error(error.message);
});
}
Original Post https://benjaminjohn.de/retrieveenvironmentvariablevalue-in-javascript






