Cannot use arrow functions with CRM WebApi v9 and typescript
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 |
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
Arrow functions aren't supported in IE (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…). Does the compilation from ts to js resolve this?
– jasonscript
Dec 13 '18 at 4:53
Nope, for IE I think you must use the 'function(value)' syntax, I mean: .then(function(val) {...}, function(err){...})
– JUtrilla
Dec 14 '18 at 10:53
I mention it because most CRM documentation assumes you are using IE :)
– jasonscript
Dec 20 '18 at 8:01
add a comment |
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 Nov 18 '18 at 15:23
Arun Vinoth
9,531132650
9,531132650
asked Nov 16 '18 at 21:21
JUtrillaJUtrilla
435
435
Arrow functions aren't supported in IE (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…). Does the compilation from ts to js resolve this?
– jasonscript
Dec 13 '18 at 4:53
Nope, for IE I think you must use the 'function(value)' syntax, I mean: .then(function(val) {...}, function(err){...})
– JUtrilla
Dec 14 '18 at 10:53
I mention it because most CRM documentation assumes you are using IE :)
– jasonscript
Dec 20 '18 at 8:01
add a comment |
Arrow functions aren't supported in IE (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…). Does the compilation from ts to js resolve this?
– jasonscript
Dec 13 '18 at 4:53
Nope, for IE I think you must use the 'function(value)' syntax, I mean: .then(function(val) {...}, function(err){...})
– JUtrilla
Dec 14 '18 at 10:53
I mention it because most CRM documentation assumes you are using IE :)
– jasonscript
Dec 20 '18 at 8:01
Arrow functions aren't supported in IE (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…). Does the compilation from ts to js resolve this?
– jasonscript
Dec 13 '18 at 4:53
Arrow functions aren't supported in IE (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…). Does the compilation from ts to js resolve this?
– jasonscript
Dec 13 '18 at 4:53
Nope, for IE I think you must use the 'function(value)' syntax, I mean: .then(function(val) {...}, function(err){...})
– JUtrilla
Dec 14 '18 at 10:53
Nope, for IE I think you must use the 'function(value)' syntax, I mean: .then(function(val) {...}, function(err){...})
– JUtrilla
Dec 14 '18 at 10:53
I mention it because most CRM documentation assumes you are using IE :)
– jasonscript
Dec 20 '18 at 8:01
I mention it because most CRM documentation assumes you are using IE :)
– jasonscript
Dec 20 '18 at 8:01
add a comment |
1 Answer
1
active
oldest
votes
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
Nov 19 '18 at 22:12
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Nov 19 '18 at 22:12
add a comment |
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
Nov 19 '18 at 22:12
add a comment |
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 Nov 18 '18 at 9:25
KrzysztofKrzysztof
13.6k23661
13.6k23661
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
Nov 19 '18 at 22:12
add a comment |
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
Nov 19 '18 at 22:12
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
Nov 19 '18 at 22:12
Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
– JUtrilla
Nov 19 '18 at 22:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Arrow functions aren't supported in IE (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…). Does the compilation from ts to js resolve this?
– jasonscript
Dec 13 '18 at 4:53
Nope, for IE I think you must use the 'function(value)' syntax, I mean: .then(function(val) {...}, function(err){...})
– JUtrilla
Dec 14 '18 at 10:53
I mention it because most CRM documentation assumes you are using IE :)
– jasonscript
Dec 20 '18 at 8:01