I want to get list item with caml query for SharePoint Hosted Add'in.
Query will returned one item.. This is my code:
function getUserData() {
var employeeList = clientContext.get_site().get_rootWeb().get_lists().getByTitle('Служители');
var userTitle = user.get_title();
var collListItem;
var oListItem;
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
"<View><Query>" +
"<Where>" +
"<Eq><FieldRef Name=\"Title\"/><Value Type=\"Text\">" + userTitle + "</Value></Eq>" +
"</Where>" +
"</Query></View>");
collListItem = employeeList.getItems(camlQuery);
clientContext.load(collListItem, 'Include(Title, empNickName, empPosition, empDepartment)');
clientContext.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);
function successHandler() {
var listItemEnumerator = collListItem.getEnumerator();
oListItem = listItemEnumerator.get_current();
userDepartment.innerHTML = oListItem.get_item('empNickName');
}
function errorHandler() {
userDepartment.innerHTML = "Request failed: " + arguments[1].get_message();
}
}
Where i'm wrong ? Thank you previously!
onQuerySucceeded
with yours - you missedlistItemEnumerator.moveNext()