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!

Yashwanth Rao
  • 340
  • 1
  • 2
  • 19

2 Answers2

2

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

moe
  • 5,267
  • 21
  • 34
  • 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 01 '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: http://sharepoint.stackexchange.com/questions/53484/how-to-return-a-value-using-context-executequeryasync & http://sharepoint.stackexchange.com/questions/108819/difference-in-clientcontext-load-and-clientcontext-executequeryasync-in-java – moe Nov 01 '16 at 10:30
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);
    });
});
Gautam Sheth
  • 30,881
  • 1
  • 35
  • 62