1
votes
function getCurrentLoginUserDetails() {
   context1 = new SP.ClientContext.get_current();
   oList = context1.get_web().get_lists().getByTitle('Employee Annual Leave Records');

   var camlQuery = new SP.CamlQuery();
   camlQuery.set_viewXml(
      '<View><Query><Where><Contains><FieldRef Name=\'Title\'/>' +
      '<Value Type=\'Text\'>L</Value></Contains></Where>' +
      '</Query></View>');

   var collListItem = oList.getItems(camlQuery);
   context1.load(collListItem);

   context1.executeQueryAsync(onQuerySucceededD,onQueryFailedD);
}


function onQuerySucceededD(sender , args) {
   var listItemInfo = '';
   var listItemEnumerator = collListItem.getEnumerator();

   while (listItemEnumerator.moveNext()) {
       var oListItem = listItemEnumerator.get_current();
       listItemInfo += '\nTitle: ' + oListItem.get_title() +
           '\nEmployee Number: ' + oListItem.get_item('Employee_x0020_Number') +
           '\nEmployed Date: ' + oListItem.get_item('Employed_x0020_Date');       
   }
   alert(listItemInfo.toString());
}


function onQueryFailedD(sender , args) {
   alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

I want to retrieve list items from a list name: Employee Annual Leave Records.

My code doesn't show me error.

But my onQuerySucceededD function alert do not show up.

I refer to this. I not really understand it, hope somebody can explain to me??

I am wondering what is the problems.

1
try to define var collListItem globally not within the functionSharique Ansari
Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on Stack Overflow. See "Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?. BTW, it's "Thanks in advance", not "Thanks in advanced".John Saunders

1 Answers

0
votes

Replace this:-

var collListItem = oList.getItems(camlQuery);

with:-

collListItem = oList.getItems(camlQuery);

and define collListItem globally like this:-

<script>
var collListItem;
</script>