I have the below sample CAML query that I built using the SPCAMLQueryHelper:

                <FieldRef Name="EndDate" />
                <Value IncludeTimeValue="TRUE" Type="DateTime">2014-12-29T00:00:00+02:00</Value>
                <FieldRef Name="EventDate" />
                <Value IncludeTimeValue="TRUE" Type="DateTime">2015-02-01T23:59:59+02:00</Value>

When I test the query in the query helper, I get the expected results (the items that are in the date range).
However, if I query from the front-end as shown below, the results are not filtered, instead, I get back all the items:

var query = new SP.CamlQuery();
var lists = web.get_lists();
var list = lists.getByTitle(listName);
context.load(list, 'Include(someFields)');
context.executeQueryAsync(function () {
    //Log out all the list items here using .getEnumerator() and .moveNext()
}, function () {

What could be the cause of the problem? Why isn't my query being applied when trying to query from the frontend?

  • 1
    You can get all the items instead filtered, if there is something wrong with query. Don't know about Client Object Model, but working with OM there is return string value from query, which may contain error.
    – Gennady G
    Jan 15, 2015 at 11:19

1 Answer 1


set_viewXml also expects opening and closing View tags. So update your query to have opening <View> and closing </View> tags. Example:

        '<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
        '<Value Type=\'Number\'>1</Value></Geq></Where></Query>' + 
  • Thank you very much, worked perfectly. Since the documentation on this seems scarce at best, do you have any suggestions on how to debug errors like these?
    – Etheryte
    Jan 15, 2015 at 13:08
  • 1
    Debugging such issues may be quite tricky, as most of the times no useful error is thrown. I have however book marked msdn.microsoft.com/en-us/library/office/…. It contains examples of doing basic operations in JSOM Jan 15, 2015 at 13:11
  • That's a good reference, again, thank you very much for your time.
    – Etheryte
    Jan 15, 2015 at 13:14

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