Skip to content

Instantly share code, notes, and snippets.

@simkessy
Created August 14, 2016 22:45
Show Gist options
  • Save simkessy/f8a4eaee9fb05301011798eba6b2a89a to your computer and use it in GitHub Desktop.
Save simkessy/f8a4eaee9fb05301011798eba6b2a89a to your computer and use it in GitHub Desktop.
var GetSites = function () {
var allSites = []
var d = $.Deferred();
//MAKE CALL FOR ALL SITES
var getCollectionSites = $().SPServices({operation: "GetAllSubWebCollection"});
//HANDLE CALL PROMISE
getCollectionSites.then(success,fail);
//EXTRACT NECESSARY PROPERTIES FROM RESPONSE
function success(resolve) {
var result = $(resolve);
result.find('Web').each(function () {
var $self = $(this);
allSites.push({
title: $self.attr('Title'),
url: $self.attr('Url')
});
});
//FUNCTION RETURNS ALL SITES
d.resolve(allSites)
};
//LOG ERROR TO CONSOLE
function fail(reject) {this.logError(reject);};
return d.promise();
}
var GetLibraries = function(sites) {
sites.map(function() {
var cc = new SP.ClientContext(site.url);
this.web = cc.get_web();
this.lists = web.get_lists()
cc.load(lists);
})
cc.executeQueryAsync(onSucceed, onFail)
function onSucceed () {
var listEnumerator = lists.getEnumerator();
var arr = [];
while (listEnumerator.moveNext()){
var oList = listEnumerator.get_current();
arr.push(oList.get_baseTemplate())
}
console.log(arr)
}
function onFail() {
console.log('Failed');
}
}
GetSites().then(function(sites){
GetLibraries(sites)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment