Tell me more ×
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

2 Answers

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. – rjcup3 Apr 4 '12 at 20:40
Obviously that is the case in javaScript though, seeing the above error that's thrown. – rjcup3 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. – rjcup3 Apr 5 '12 at 0:45

Are you trying to call get_count() after the query is finished executing? Otherwise the object will be null. It isn't actually retrieved until the ExecuteQuery() or ExecuteQueryAsync(succeed_method, fail_method) call is completed.

share|improve this answer
i tried adding context.ExecuteQuery() and i got a stack unwind on that execution, but yes its all called after. In firebug i have my object set as a value. – Dr.Denis McCracleJizz Apr 4 '12 at 18:46
Where do you instantiate currentweb? – rjcup3 Apr 4 '12 at 18:53
yes i did, outside the function but i did. I updated the code to put it inside the function but the result is the same, stack unwind on ExecuteQuery – Dr.Denis McCracleJizz Apr 4 '12 at 18:59

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.