I am attempting to display two different lists on a page, and it seems the 2 listItemEnumerator are having conflict. If I strip everything but my second Enumerator (listItemEnumerator1.moveNext), it seems to work. I have tried various combos, and yet can't get both lists to display at the same time. If I get one to work, the one that appears "on top" in the code will display.
My code:
$(function () {
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
});
function retrieveListItems() {
var clientContext = new SP.ClientContext();
var oList = clientContext.get_web().get_lists().getByTitle('News Archives');
var oList1 = clientContext.get_web().get_lists().getByTitle('Links');
var camlQuery = new SP.CamlQuery();
var camlQuery1 = new SP.CamlQuery();
camlQuery.set_viewXml(
'<View><Query><Where><Leq><FieldRef Name="Publication_x0020_Date" /><Value Type="DateTime"><Today /></Value></Lq></Where><OrderBy><FieldRef Name="Publication_x0020_Date" Ascending="False"/></OrderBy></Query><RowLimit>20</RowLimit></View>'
);
this.collListItem = oList.getItems(camlQuery);
camlQuery1.set_viewXml(
'<View><Query><OrderBy><FieldRef Name="SortOrder" Ascending="True"/></OrderBy><RowLimit>1</RowLimit></Query></View>'
);
this.collListItem1 = oList.getItems(camlQuery1);
clientContext.load(collListItem);
clientContext.load(collListItem1);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemInfo1 = '';
var listItemEnumerator = collListItem.getEnumerator();
var listItemEnumerator1 = collListItem1.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var publicationDate = oListItem.get_item('Publication_x0020_Date');
var formatDate = publicationDate.format('d MMMM yyyy');
listItemInfo +=
'<div class="newsitem">' +
'<h1 class="news-title"><a href="' + oListItem.get_item('Title0').get_url() + '">' + oListItem.get_item('Title0').get_description() + '</a></h1>' +
'<p>' + oListItem.get_item('Title') + ', ' + formatDate + '</p>' +
oListItem.get_item('Summary_x0020__x002b__x0020_Medi') +
'</div>';
}
while (listItemEnumerator1.moveNext()) {
var oListItem1 = listItemEnumerator1.get_current();
listItemInfo1 +=
'<a class= "button '+ oListItem1.get_item('ycob') +'" href="' + oListItem1.get_item('Link').get_url() + '">' + oListItem1.get_item('Link').get_description() + '</a>';
}
$("#newsfeed").html(listItemInfo);
$("#newsfeed").html(listItemInfo);
}
Where is my logic flawed?