Does anyone have an example Javascript to achieve this?
https://{yourOrg}.crm.dynamics.com/api/data/v9.2/RetrieveEnvironmentVariableValue(DefinitionSchemaName='{envVariableSchemaName}')
var Sdk = window.Sdk || {};
Sdk.RetrieveEnvironmentVariableValueRequest = function(DefinitionSchemaName) {
this.DefinitionSchemaName = DefinitionSchemaName;
};
// NOTE: The getMetadata property should be attached to the function prototype instead of the
// function object itself.
Sdk.RetrieveEnvironmentVariableValueRequest.prototype.getMetadata = function () {
return {
boundParameter: null, // not boud function
operationName: "RetrieveEnvironmentVariableValue",
operationType: 1, // because it is a function
parameterTypes: {
"DefinitionSchemaName": { // Parameter name
"typeName": "Edm.String", // Copy the type from the parameter in the function's Microsoft learn page
"structuralProperty": 1 // Primitive type, we are looking for a string which is the environment variable name
}
},
};
};
var retrieveEnvironmentVariableValueRequest = new Sdk.RetrieveEnvironmentVariableValueRequest("{envVariableSchemaName}");
Xrm.WebApi.online.execute(retrieveEnvironmentVariableValueRequest).then(function (response) {
if (response.ok) {
return response.json(); // handle the promise result, you can either return or use the .then method
}
})
.catch(function(error) {
debugger; console.log(error.message);
// handle error conditions
});
environmentvariabledefinition
async GetEnvironmentVariableValue function (name) {
let results = await Xrm.WebApi.retrieveMultipleRecords("environmentvariabledefinition", `?$filter=schemaname eq '${name}'&$select=environmentvariabledefinitionid&$expand=environmentvariabledefinition_environmentvariablevalue($select=value)`);
if (!results || !results.entities || results.entities.length < 1) return null;
let variable = results.entities[0];
if (!variable.environmentvariabledefinition_environmentvariablevalue || variable.environmentvariabledefinition_environmentvariablevalue.length < 1) return null;
return variable.environmentvariabledefinition_environmentvariablevalue[0].value;
}
André Arnaud de Cal... 291,642 Super User 2024 Season 2
Martin Dráb 230,371 Most Valuable Professional
nmaenpaa 101,156