Skip to content

Instantly share code, notes, and snippets.

@vgrem vgrem/enumWebs.js
Created Apr 11, 2015

Embed
What would you like to do?
Enumerate webs of site collection using SharePoint JSOM
function enumWebs(propertiesToRetrieve, success,error)
{
var ctx = SP.ClientContext.get_current();
var rootWeb = ctx.get_site().get_rootWeb();
var result = [];
var level = 0;
ctx.load(rootWeb,propertiesToRetrieve);
result.push(rootWeb);
var colPropertiesToRetrieve = String.format('Include({0})',propertiesToRetrieve.join(','));
var enumWebsInner = function(web,result,success,error)
{
level++;
var ctx = web.get_context();
var webs = web.get_webs();
ctx.load(webs,colPropertiesToRetrieve);
ctx.executeQueryAsync(
function(){
for(var i = 0; i < webs.get_count();i++){
var web = webs.getItemAtIndex(i);
result.push(web);
enumWebsInner(web,result,success,error);
}
level--;
if (level == 0 && success)
success(result);
},
error);
};
enumWebsInner(rootWeb,result,success,error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.