Cannot use arrow functions with CRM WebApi v9 and typescript
up vote
0
down vote
favorite
I´m working on the upgrade of the js code to the new V9 version of Dynamics 365 and I cannot use arrow functions when using Xrm.WebApi (also upgrading js to ts).
For example, this does not 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("E----", () => { });
});
but this does (uglier 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 I´m receiving is:
Xrm.WebApi.retrieveMultipleRecords(...).then(...).catch is not a function
Basically tells me that 'catch' is not valid but I don´t know why it isn´t since it is ok for the ts compiler... I also tried configuring tsconfig file to output on es5 and es2017 but it didn´t work either.
so... can arrow functions be used with Xrm.WebApi? if so... what I´m doing wrong/not doing?
Thanks in advance!
typescript dynamics-crm dynamics-crm-online dynamics-crm-webapi
add a comment |
up vote
0
down vote
favorite
I´m working on the upgrade of the js code to the new V9 version of Dynamics 365 and I cannot use arrow functions when using Xrm.WebApi (also upgrading js to ts).
For example, this does not 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("E----", () => { });
});
but this does (uglier 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 I´m receiving is:
Xrm.WebApi.retrieveMultipleRecords(...).then(...).catch is not a function
Basically tells me that 'catch' is not valid but I don´t know why it isn´t since it is ok for the ts compiler... I also tried configuring tsconfig file to output on es5 and es2017 but it didn´t work either.
so... can arrow functions be used with Xrm.WebApi? if so... what I´m doing wrong/not doing?
Thanks in advance!
typescript dynamics-crm dynamics-crm-online dynamics-crm-webapi
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I´m working on the upgrade of the js code to the new V9 version of Dynamics 365 and I cannot use arrow functions when using Xrm.WebApi (also upgrading js to ts).
For example, this does not 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("E----", () => { });
});
but this does (uglier 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 I´m receiving is:
Xrm.WebApi.retrieveMultipleRecords(...).then(...).catch is not a function
Basically tells me that 'catch' is not valid but I don´t know why it isn´t since it is ok for the ts compiler... I also tried configuring tsconfig file to output on es5 and es2017 but it didn´t work either.
so... can arrow functions be used with Xrm.WebApi? if so... what I´m doing wrong/not doing?
Thanks in advance!
typescript dynamics-crm dynamics-crm-online dynamics-crm-webapi
I´m working on the upgrade of the js code to the new V9 version of Dynamics 365 and I cannot use arrow functions when using Xrm.WebApi (also upgrading js to ts).
For example, this does not 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("E----", () => { });
});
but this does (uglier 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 I´m receiving is:
Xrm.WebApi.retrieveMultipleRecords(...).then(...).catch is not a function
Basically tells me that 'catch' is not valid but I don´t know why it isn´t since it is ok for the ts compiler... I also tried configuring tsconfig file to output on es5 and es2017 but it didn´t work either.
so... can arrow functions be used with Xrm.WebApi? if so... what I´m doing wrong/not doing?
Thanks in advance!
typescript dynamics-crm dynamics-crm-online dynamics-crm-webapi
typescript dynamics-crm dynamics-crm-online dynamics-crm-webapi
edited yesterday
Arun Vinoth
8,617132345
8,617132345
asked Nov 16 at 21:21
JUtrilla
384
384
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I don't think the problem is caused by arrow functions. I think catch
is the problem. Compiler won't tell you anything, if return value is of type any
. I don't know if that is the case, but if you look into CRM API, you will see following signature:
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);
There is no mention of catch
, but instead you can pass errorCallback
to then
.
BTW this is the way, you pass errorHandler
in the second example.
So try this:
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);
}
},
error => {
console.log("ERROR -> entitlementSlaManagementOnUpdate: ", error);
Xrm.Utility.alertDialog("E----", () => { });
});
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I don't think the problem is caused by arrow functions. I think catch
is the problem. Compiler won't tell you anything, if return value is of type any
. I don't know if that is the case, but if you look into CRM API, you will see following signature:
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);
There is no mention of catch
, but instead you can pass errorCallback
to then
.
BTW this is the way, you pass errorHandler
in the second example.
So try this:
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);
}
},
error => {
console.log("ERROR -> entitlementSlaManagementOnUpdate: ", error);
Xrm.Utility.alertDialog("E----", () => { });
});
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
add a comment |
up vote
1
down vote
accepted
I don't think the problem is caused by arrow functions. I think catch
is the problem. Compiler won't tell you anything, if return value is of type any
. I don't know if that is the case, but if you look into CRM API, you will see following signature:
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);
There is no mention of catch
, but instead you can pass errorCallback
to then
.
BTW this is the way, you pass errorHandler
in the second example.
So try this:
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);
}
},
error => {
console.log("ERROR -> entitlementSlaManagementOnUpdate: ", error);
Xrm.Utility.alertDialog("E----", () => { });
});
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I don't think the problem is caused by arrow functions. I think catch
is the problem. Compiler won't tell you anything, if return value is of type any
. I don't know if that is the case, but if you look into CRM API, you will see following signature:
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);
There is no mention of catch
, but instead you can pass errorCallback
to then
.
BTW this is the way, you pass errorHandler
in the second example.
So try this:
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);
}
},
error => {
console.log("ERROR -> entitlementSlaManagementOnUpdate: ", error);
Xrm.Utility.alertDialog("E----", () => { });
});
I don't think the problem is caused by arrow functions. I think catch
is the problem. Compiler won't tell you anything, if return value is of type any
. I don't know if that is the case, but if you look into CRM API, you will see following signature:
Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);
There is no mention of catch
, but instead you can pass errorCallback
to then
.
BTW this is the way, you pass errorHandler
in the second example.
So try this:
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);
}
},
error => {
console.log("ERROR -> entitlementSlaManagementOnUpdate: ", error);
Xrm.Utility.alertDialog("E----", () => { });
});
answered yesterday
Krzysztof
13.5k23560
13.5k23560
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
add a comment |
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
5 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345561%2fcannot-use-arrow-functions-with-crm-webapi-v9-and-typescript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown