I want to get all list items from all lists in SharePoint 2010 with JavaScript. I always get the error:
SCRIPT5022: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Here is my code:
ExecuteOrDelayUntilScriptLoaded(receivedAllLists, "SP.js");
function receivedAllLists() {
var clientContext = new SP.ClientContext.get_current();
var oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();
clientContext.load(collList);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onreceivedAllListsSucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onreceivedAllListsSucceeded() {
var clientContext = new SP.ClientContext.get_current();
var oWebsite = clientContext.get_web();
var listInfo = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
oList = oWebsite.get_lists().getByTitle(listTitle);
var splistquery = new SP.CamlQuery();
splistitems = oList.getItems(splistquery);
clientContext.load(splistitems, 'Include(Id)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onrecieveAllListItemsSucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
function onQueryFailed(sender, args) {
alert('Fail');
}
function onrecieveAllListItemsSucceeded() {
var listItemInfo = '';
var listItemEnumerator = splistitems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var currentlistitem = listItemEnumerator.get_current();
}
}