I am trying to create a function which should loop through all lists on current web and display their current item count.
My code so far:
<!-- language: lang-js -->
ZN.updateDocumentCount = function () {
var context = new SP.ClientContext.get_current();
this.spLists = context.get_web().get_lists();
context.load(this.spLists, "Include(DefaultDisplayFormUrl)");
context.executeQueryAsync(Function.createDelegate(this, ZN.updateDocumentCount.Success), Function.createDelegate(this, ZN.updateDocumentCount.Failure));
}
ZN.updateDocumentCount.Success = function () {
var enumerator = this.spLists.getEnumerator();
while (enumerator.moveNext()) {
var list = enumerator.get_current();
var count = list.get_itemCount(); // <-- I get an error here
alert(count);
}
SP.UI.Status.addStatus("Success", "All document counts are up-to-date.", false);
};
When the script gets to the part where it should get list.get_itemCount()
it throws the following error:
The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
How can I otherwise achieve getting item counts for all lists?