0

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 2

0

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());
    });   
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.