I am trying to run a CAML query to sort through some data. Once the page finishes loading i do not get the results i want. I checked the functions and it turns out that for some reason, my CAML query returns undefined
. It only does this after it is passed in the set_viewXml()
function. Code provided below:
var runQuery = function (dateObj, query, success, failure, context) {
var camlQuery = new SP.CamlQuery();
alert(query); // shows the CAML query
alert(camlQuery.set_viewXml(query(dateObj))); // shows me undefined
camlQuery.set_viewXml(query(dateObj));
items = list.getItems(camlQuery);
context.load(items);
context.executeQueryAsync(success, failure);
};
Here is the CAML:
"<View>" +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq>" +
"<FieldRef Name='EventStartDate' />" +
"<Value Type='DateTime' IncludeTimeValue='FALSE'>" +
dateObj.toISOString() +
"</Value>" +
"</Eq>" +
"<Eq><FieldRef Name=\"QueryID\" /><Value Type=\"Text\">2216</Value></Eq>" +
"</And>" +
"</Where>" +
"<GroupBy><FieldRef Name='EventName'></FieldRef></GroupBy>"+
"<OrderBy><FieldRef Name='EventStartDate' /><FieldRef Name='EventEndDate' /><FieldRef Name='EventName' /></OrderBy>" +
"</Query>" +
"</View>";
I am pretty sure there is something wrong with the CAML query because i do not work with it on a day to day basis.
I have this code running fine in another app and when I alert(alert(camlQuery.set_viewXml(query(dateObj)));)
I am able to see the full CAML query build (it does not return undefined
). Not sure if that helps any.