I am querying a list using JavaScript, from time to time the list items are retrieved, however, there are times that it returns an access denied error.
var web = clientContext.get_web();
var list = clientContext.get_web().get_lists().getByTitle("Employee Hours Profile");
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View>' +
'<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>xItemTitle]</Value></Eq></Where></Query>' +
'<ViewFields>' +
'<FieldRef Name='Title' />' +
'</ViewFields>' +
'<RowLimit>1</RowLimit>' +
'</View>');
var listItems = list.getItems(camlQuery);
clientContext.load(listItems);
clientContext.executeQueryAsync(onSuccess, onFail);
function onSuccess() {
var listItemEnumerator = listItems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
var title = listItem.get_item('Title');
}
NWF$("#" + varTitle).val(title);
}
function onFail(sender, args) {
alert("Error");
}