Skip to content

Instantly share code, notes, and snippets.

@PaulSpoerry
Created July 5, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulSpoerry/bd2f2a99c475cc3a0c06689c953fdc1a to your computer and use it in GitHub Desktop.
Save PaulSpoerry/bd2f2a99c475cc3a0c06689c953fdc1a to your computer and use it in GitHub Desktop.
List all subsites within a SharePoint container by iterating over SPServices.SPGetCurrentSite()
jQuery.noConflict();
(function( $ ) {
//inject SPServices
var sps = document.createElement('script');
sps.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js";
document.getElementsByTagName('head')[0].appendChild(sps);
// Code in here
var tree = $('#treeviewList');
var rootsite = $().SPServices.SPGetCurrentSite();
var siteEnd = false;
getSubSite(rootsite);
function getSubSite(url){
$().SPServices({
operation: "GetWebCollection",
webURL: url,
async: true,
completefunc: function(xData, Status) {
var siteUrl;
var siteCount = $(xData.responseXML).find("Web").length;
if(siteCount == 0){
console.log("end of branch");
siteEnd = true;
}else{
$(xData.responseXML).find("Web").each(function() {
siteUrl = $(this).attr("Url");
console.log(siteUrl);
getSubSite(siteUrl);
});
}
}
});
}
// End code in here
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment