Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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>' +
                                '<Query>'+
                                    '<Where>'+
                                        '<IsNotNull>' +
                                            '<FieldRef Name="ID" />'+
                                        '</IsNotNull>' +
                                    '</Where>'+
                                '</Query>'+
                                '<ViewFields>'+
                                    '<FieldRef Name="Name"/>'+
                                '</ViewFields>'+
                            '</View>');


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

    this.docList= colList.getItems(query);
    context.load(this.docList);
    context.ExecuteQuery();

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

context.ExecuteQuery is not a function
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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. –  RJ Cuthbertson Apr 4 '12 at 20:40
    
Obviously that is the case in javaScript though, seeing the above error that's thrown. –  RJ Cuthbertson Apr 4 '12 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 –  Per Jakobsen Apr 4 '12 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. –  RJ Cuthbertson Apr 5 '12 at 0:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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