
I have a simple asynchronous function to get the current enviorment variable .I am trying to use this function marked in red in another sync function but getting value as promise pending. I know I am making an error calling this function. Can I get the idea how to call it and utilize it?
// Asysc to get enviornment variable
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;// returning the value that I want. current value of env varibale
}
//Calling it to another function and getting value as promise pending
...rest od the code..no need to see..
}} Actually, your code has used the Promise in this line: Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then
As the openAlertDialog function also returns a Promise object.
So just keep going like this:
getEnvironmentVariable("new_variable").then(
function (envURL) {
// do your logic here
}, function (error) {
// deal with error
}
);