AnsweredAssumed Answered

Using JavaScript to Query List

Question asked by jekcalingan on Jul 28, 2015
Latest reply on Mar 4, 2016 by francois

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\'>[ItemTitle]</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");

}

Outcomes