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!

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

2 Answers 2

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.

2
  • 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); }); Commented Nov 1, 2016 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/… Commented Nov 1, 2016 at 10:30

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.