make code wait for async 8.2
The async function to wait
function getSetting (settingName)
{
var req = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
// Setup our listener to process compeleted requests
req.onreadystatechange = function () {
// Only run if the request is complete
if (req.readyState !== 4) return;
// Process the response
if (req.status >= 200 && req.status < 300) {
// If successful
resolve
( req );
} else {
// If failed
reject(
alert ("multiple setting with the name :" + settingName)
);
}
};
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/query, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.send();
}
);
}
the function that call
async function setDefaultFrom(executionContext)
{
debugger;
var results = await getSetting (param);
var defaultFrom = JSON.parse(results.response);
}
Commentaires
Enregistrer un commentaire