I have to port an AngularJS app to Angular4 which now uses promises and have no clue how I can use this with the executeQueryAsync() method from JSOM. I have also not found any documentation to this on the internet. Can someone help me how to use this method in my Angular4 service please? Just need the syntax.

Here is my old code as example:

 getAllStatusReps($scope) {
    const deferred = $q.defer();

    const ctx = SP.ClientContext.get_current();
    const web = ctx.get_web();

    const statusList = web.get_lists().getByTitle(this.statusListName);
    const twitterList = web.get_lists().getByTitle(this.twitterListName);

    const statReps = statusList.getItems(this.getQueryForAllStatusReps());
    const twitReps = twitterList.getItems(this.getQueryForAllStatusReps());
    const queryText = `
          <Where><IsNotNull><FieldRef Name=\'EPMStatusDate\' /></IsNotNull></Where>
          <OrderBy><FieldRef Name=\'ID\' Ascending= \'False\' /></OrderBy>

    const statCamlQuery = new SP.CamlQuery();
    statCamlQuery.set_viewXml(String.format(queryText, this.getViewFields(true, false)));
    const lastStatRep = statusList.getItems(statCamlQuery);

    const twitCamlQuery = new SP.CamlQuery();
    twitCamlQuery.set_viewXml(String.format(queryText, this.getViewFields(false, false)));
    const lastTwitRep = twitterList.getItems(twitCamlQuery);



      function () {
        // to emulate empty response:
        // statReps.$2_1 = [];
        // twitReps.$2_1 = [];
          statReps: statReps,
          twitReps: twitReps,
          lastStatRep: lastStatRep,
          lastTwitRep: lastTwitRep
      function (sender, args) {
        deferred.reject('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

    return deferred.promise;
  • I am also struggling with the same issue. Did you get any solution yet? Commented Nov 12, 2017 at 19:04
  • Unfortunately not. I switched to REST calls and I am happy with it. It was a bit of work, but now I am future proof and independent. Commented Nov 13, 2017 at 9:45
  • If you moved to rest, then you can try PNP solution...It gives all the functionalities except taxonomy population...I got another work around.You can have a look into this. social.msdn.microsoft.com/Forums/office/en-US/… Commented Nov 14, 2017 at 15:45
  • I know PNP, but it was not really suitable for my needs at this time. Commented Nov 14, 2017 at 15:50


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.