As the title says, I have a caml query that is invoked through JSOM
code which always returns an empty collection. I am querying the list based on two columns: One being of type User
and the other of being of type Text
.
Here are the snipps:
$("#searchUser").click(function () {
var _BizRepo = Biz.Services.SearchRepository;
var currentCtx = SP.ClientContext.get_current();
var picker = SPClientPeoplePicker.SPClientPeoplePickerDict.clientPeoplePicker_TopSpan.GetAllUserInfo();
var user = picker[0].Key;
var selectedYear = $("#year").val();
var metricsRaw = _BizRepo.GetMetricsForUser(currentCtx, user, selectedYear, "Test");
if (metricsRaw === undefined) { //Always end up in this block
$("#NoResults").html("No results found.");
}
//ommitted for brevity...
GetMetricsForUser() does the actual querying.
GetMetricsForUser: function (currentCtx, user, selectedYear, docLibName) {
var metricsList = currentCtx.get_web().get_lists().getByTitle("Metrics for " + docLibName);
var query = new SP.CamlQuery();
query.set_viewXml("<Where><And><Eq><FieldRef Name='User' /><Value Type='User'>" + user + "</Value></Eq><Eq><FieldRef Name='Year' /><Value Type='Text'>" + selectedYear + "</Value></Eq></And></Where>");
var itemCollection = metricsList.getItems(query);
currentCtx.load(itemCollection);
currentCtx.executeQueryAsync(function () { return itemCollection; }, function (sender, args) { console.log(args.get_message()); });
}
No exceptions are thrown when stepping through the code, so i'm completely lost. Am I passing an incorrect user type of object to the query perhaps?
<View><Query>
and a closing</Query></View>