I am currently in the process of upgrading the JavaScript code to the latest V9 version of Dynamics 365, and I am facing an issue where I cannot utilize arrow functions when working with Xrm.WebApi (also transitioning from JavaScript to TypeScript).
For instance, the following code snippet does not seem to work:
Xrm.WebApi.retrieveMultipleRecords(
'mks_entitlementline',
`$select=mks_name, _mks_parententitlementid_value&$filter=_mks_parententitlementid_value eq '${eId}'`).then(
(results) => {
if (!this.commonUtils.isUndefinedOrNull(results) && results.entities.length > 0) {
this.usesELS();
} else {
this.notUsingELS();
}
// filter contact lookup
this.filterContactLookup("", eId);
this.refreshPriorities(eId);
if (this.commonUtils.isUndefinedOrNull(this.formContext.getAttribute<Xrm.Attributes.LookupAttribute>('primarycontactid').getValue())) {
this.formContext.getControl<Xrm.Controls.LookupControl>('primarycontactid').setDisabled(false);
}
}).catch(error => {
console.log("ERROR -> entitlementSlaManagementOnUpdate: ", error);
Xrm.Utility.alertDialog("Error----", () => { });
});
However, the following piece of code seems to function (though appearing less elegant in my opinion):
Xrm.WebApi.retrieveRecord("role", searchedId, "$select=name")
.then(
function (role: { roleid: string, name: string }) {
outArr.push({ Id: role.roleid, Name: role.name, Type: "role" });
if (rolesAndTeams.length === outArr.length) {
if (!error) {
_onOk(outArr);
}
_onErr(errorObject)
}
},
function (err) {
errorObject = err;
error = true;
})
The error message I'm encountering states:
Xrm.WebApi.retrieveMultipleRecords(...).then(...).catch is not a function
This essentially informs me that 'catch' is invalid, but I am unsure why it is flagged as such since the TypeScript compiler accepts it... I have also attempted configuring the tsconfig file to output on es5 and es2017 without success.
Therefore, the question remains - can arrow functions be utilized with Xrm.WebApi? If so, what am I doing wrong or failing to do?
Thank you in advance!