The page containing the results belongs to one of the sibling sites and I would like to be able to loop through the site collections dynamically without providing a list of collections first.
2 Answers
If you want to get all of the webs that are siblings of the current web you can specify the rootWeb
of the current site then get all of its children:
var myCtx = SP.ClientContext.get_current();
var mySite = myCtx.get_site();
var rootWeb = mySite.get_rootWeb();
var siblingWebs = rootWeb.get_webs();
var web;
//webs have a lot of information in them; suggest using an include filter
//for production
myCtx.load(siblingWebs);
myCtx.executeQueryAsync(function () {
for (var i = 0; i < siblingWebs.get_count(); i++) {
web = siblingWebs.itemAt(i);
console.log(web.get_title());
}
}, function (sender, args) {
console.log(args.get_message());
});
You just need to specify the server relative url of the sibling site.
http://<endpoint><serverrelativeurl of the sibling site>/_api/web/GetSubwebsFilteredForCurrentUser(nwebtemplatefilter,nconfigurationfilter)