I built a CAML query using U2U CAML Query Builder and it works when I execute it in the builder, but when I go to JSOM in SharePoint, I get the entire list and none of the filters from the query work.
Query
<Query>
<Where>
<And>
<Geq>
<FieldRef Name='Created1' />
<Value IncludeTimeValue='TRUE' Type='DateTime'>2014-10-29T10:07:07Z</Value>
</Geq>
<Leq>
<FieldRef Name='Created1' />
<Value IncludeTimeValue='TRUE' Type='DateTime'>2014-11-04T09:07:08Z</Value>
</Leq>
</And>
</Where>
<OrderBy>
<FieldRef Name='Title' Ascending='True' />
</OrderBy>
</Query>
Here is the code that isn't working. What am I doing wrong?
function retrieveListItemsInclude() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Incidents');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<Query><Where><And><Geq><FieldRef Name=\'Created1\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>2014-10-29T10:07:07Z</Value></Geq><Leq><FieldRef Name=\'Created1\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>2014-11-04T09:07:08Z</Value></Leq></And></Where><OrderBy><FieldRef Name=\'Title\' Ascending=\'True\' /></OrderBy></Query>');
window.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem, 'Include(Title, Created1, Severity)');
clientContext.executeQueryAsync(Function.createDelegate(this, window.onQuerySucceeded), Function.createDelegate(this, window.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nTitle: ' + oListItem.get_item('Title') +
'\nCreated: ' + oListItem.get_item('Created1');
}
console.log(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}