I am currently trying to determine the length of a list that is located on my SharePoint site. I am using a Caml query to retrieve the items in my list, but I can not figure out how to get the length of the result. I am using the Client Object Model and javascript / Ajax / jquery etc...

var context = new SP.ClientContext.get_current();
    var query = new SP.CamlQuery();
    var currentweb = context.get_web();

    query.set_viewXml('<View>' +
                                        '<IsNotNull>' +
                                            '<FieldRef Name="ID" />'+
                                        '</IsNotNull>' +
                                    '<FieldRef Name="Name"/>'+

    var colList= currentweb.get_lists().getByTitle("MyList");

    this.docList= colList.getItems(query);

When the code runs context.ExecuteQuery() the console prints out this.

context.ExecuteQuery is not a function

1 Answer 1


The javaScript (and SilverLight) client object model doesn't implement clientContext.ExecuteQuery only the ExecuteQueryAsync(successDelegate, failDelegate).

  • Sure it does. At least in SilverLight. I've used it before, and just checked to make sure I wasn't crazy. It's there. It works. Apr 4, 2012 at 20:40
  • Obviously that is the case in javaScript though, seeing the above error that's thrown. Apr 4, 2012 at 20:42
  • @rjcup3 Well the SilverLight has it, but only if running outside UI thread, so it's generally discouraged to use it. JavaScript doesn't even have it, which is probably a better approach Apr 4, 2012 at 21:10
  • Why would you want to perform non-UI actions on the UI thread? I only use the UI thread for the UI... I do generally use the asynchronous model, but I have used queries synchronously if they need to be executed in direct succession (ie: data from query A is used in query B, which returns data used in query C). It's just easier to keep them all in one function. Apr 5, 2012 at 0:45

Your Answer

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

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