I'm creating a status page in the site collection that needs to display List Status of all the subs below site collection. All the sub-sites have the same list 'Projects'. So the idea is to iterate all subwebs and report on the list in a tabular format. When I don't call function 'retrieveListItemsInclude()' then all the sub-sites are listed, when I do call the function an alert box appears but execution halts after 1st iteration. The function doesn't seem to return.
ExecuteOrDelayUntilScriptLoaded(RetrieveSites,"sp.js");
function RetrieveSites()
{
currentcontext = new SP.ClientContext.get_current();
currentweb = currentcontext.get_web();
//this.subsites = currentweb.get_webs();
this.subsites = currentweb.getSubwebsForCurrentUser(null);
currentcontext.load(this.subsites);
currentcontext.executeQueryAsync(Function.createDelegate(this, this.SitesExecuteOnSuccess),Function.createDelegate(this, this.SitesExecuteOnFailure));
}
function SitesExecuteOnSuccess(sender, args)
{
//var HTMLContent = '';
var enum1 = this.subsites.getEnumerator();
el = document.getElementById('LKMSubWebs');
var HTMLContent;
while (enum1.moveNext())
{
var Site = enum1.get_current();
//alert('hi123');
//Add Subsites to HTML Content
HTMLContent += '\n' + '<img title="css" alt="css" src="/_layouts/15/images/SharePointFoundation16.png" border="0"> ' + '<a class=subsitecls href='+ Site.get_serverRelativeUrl()+'>'+Site.get_title()+'</a> </br>';
//RootElement.append('<a class=subsitecls href='+ siteTitle+'>'+siteTitle+'</a> </br>');
}
//set div to content
el.innerHTML = HTMLContent;
retrieveListItemsInclude();
}
function SitesExecuteOnFailure(sender, args)
{
alert("error");
//alert(args.get_message());
}
function retrieveListItemsInclude() {
var clientContext = new SP.ClientContext.get_current();//(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Project');
var camlQuery = new SP.CamlQuery();
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem, 'Include(Id, DisplayName, HasUniqueRoleAssignments)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += '\nID: ' + oListItem.get_id() +
'\nDisplay name: ' + oListItem.get_displayName() +
'\nUnique role assignments: ' + oListItem.get_hasUniqueRoleAssignments();
}
alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}