Created
March 16, 2019 02:13
-
-
Save samperrow/f74814ea795ee4b818bf2b9ed69e55c0 to your computer and use it in GitHub Desktop.
Filter down array of subsite URL's and return the ones that have the specified list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Part 2. | |
* Filter down array of subsite URL's and return the ones that have the specified list. | |
* @param is an array of strings, each of which is a subsite URL. | |
*/ | |
function GetListGuidsForSubsites(sites) { | |
var targetSites = []; | |
var siteIndex = 0; | |
function controller() { | |
if (siteIndex < sites.length) { | |
getListGuid(sites[siteIndex]); | |
} else if (targetSites.length > 0) { | |
console.log('Done collecting list guids.'); | |
return GetListAndFormData(targetSites); | |
} | |
} | |
controller(); | |
function createTargetFiles(siteURL) { | |
var arr = []; | |
for (var i = 0; i < sourceFiles.length; i++) { | |
arr.push({ filePath: siteURL + '/Lists/' + listName + '/' + sourceFiles[i].title + '.aspx', title: sourceFiles[i].title }); | |
} | |
return arr; | |
} | |
function getListGuid(siteURL) { | |
var currentcontext = new SP.ClientContext(siteURL); | |
var list = currentcontext.get_web().get_lists().getByTitle(listName); | |
currentcontext.load(list, 'Id'); | |
currentcontext.executeQueryAsync( | |
function() { | |
var listGuid = list.get_id().toString(); | |
console.log('List found at ' + siteURL); | |
targetSites.push({ | |
subsiteURL: siteURL, | |
listGUID: listGuid, | |
listName: listName, | |
targetForms: createTargetFiles(siteURL) | |
}); | |
siteIndex++ | |
return controller(); | |
}, | |
function (sender, args) { | |
cosole.warn(args.get_message()); | |
siteIndex++ | |
return controller(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment