0

I have some JSOM code in my master page(seattle.master). The code runs until load() method on the context object but executeQueryAsync is not executing.

    SP.SOD.executeOrDelayUntilScriptLoaded(function(){

                        var context = SP.ClientContext.get_current();   
                        var web = context.get_web();            
                        var list = web.get_lists().getByTitle(list_title);
                        context.load(list);
                        context.executeQueryAsync(function(data){
                        console.log(data);
                        },
                          function(data,args){
                            console.log(args);
                        });
},'sp.js');             

Neither of the log statements in the success nor the error function is getting printed.

Thanks!

  • 1
    Are you specifying the list's title for getByTitle somewhere - is it just hidden in this question? – moe Nov 1 '16 at 10:04
  • Yes, it is not specified in this question but it holds a value for the list title. – Yashwanth Rao Nov 1 '16 at 10:05
2

Use your code like below:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
    var context = SP.ClientContext.get_current();   
    var web = context.get_web();            
    var list = web.get_lists().getByTitle(list_title);
    context.load(list);
    context.executeQueryAsync(function(data){
    console.log(data);
    },
      function(data,args){
        console.log(args);
    });
});
2

executeQueryAsync requires both succeededCallback and failedCallback parameters per SP.ClientContext.executeQueryAsync method (sp.js). I think you are missing the failedCallback.

  • I do have two callbacks in my code. two callback functions inside executeQueryAsync context.executeQueryAsync(function(data){ console.log(data); }, function(data,args){ console.log(args); }); – Yashwanth Rao Nov 1 '16 at 10:19
  • @YashwanthRao right! Pardon my sloppiness. I think this case might fall under the definition of asynchronous and the requirements it sets. There are a couple of useful sources to explain it further over here: sharepoint.stackexchange.com/questions/53484/… & sharepoint.stackexchange.com/questions/108819/… – moe Nov 1 '16 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.