Cannot use arrow functions with CRM WebApi v9 and typescript











up vote
0
down vote

favorite
1












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!










share|improve this question




























    up vote
    0
    down vote

    favorite
    1












    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!










    share|improve this question


























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      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!










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Arun Vinoth

      8,617132345




      8,617132345










      asked Nov 16 at 21:21









      JUtrilla

      384




      384
























          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----", () => { });
          });





          share|improve this answer





















          • Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
            – JUtrilla
            5 hours ago











          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',
          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
          });


          }
          });














           

          draft saved


          draft discarded


















          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








          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----", () => { });
          });





          share|improve this answer





















          • Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
            – JUtrilla
            5 hours ago















          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----", () => { });
          });





          share|improve this answer





















          • Thanks Krzysztof!, it works and it´s much better than having to contantly write function ().
            – JUtrilla
            5 hours ago













          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----", () => { });
          });





          share|improve this answer












          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----", () => { });
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy