promise example
the promise
async function getrecord(recordtype,recordid) {
return new Promise(resolve => {{
resolve(Xrm.WebApi.retrieveRecord(recordtype, recordid ).then(
function success(result)
{
// perform operations on record retrieval
if (result)
{
return result;
}
},
function (error)
{
Xrm.Navigation.openAlertDialog(error.message);
}
)
);
}});
the function that call the promise
async function onChange_regarding(executionContext)
{
var formContext = executionContext.getFormContext();
var regarding = formContext.getAttribute("regardingobjectid").getValue();
var mycurrentSubject = formContext.getAttribute("subject").getValue();
if (regarding != null)
{
var entType = regarding[0].entityType;
if (entType == "incident" && mycurrentSubject == null )
{
var caserecord = await getrecord("incident", regarding[0].id);
var caseSubject= caserecord["_subjectid_value@OData.Community.Display.V1.FormattedValue"];
var mytitle;
if (caseSubject != null && caseSubject != "undifined" )
mytitle = caseSubject +" : " + caserecord.ticketnumber;
else
mytitle = caserecord.ticketnumber;
// alert (mytitle);
formContext.getAttribute("subject").setValue(mytitle);
}
}
}
Commentaires
Enregistrer un commentaire