Skip to content

Instantly share code, notes, and snippets.

@samperrow
samperrow / Get Subsite URL's
Last active March 16, 2019 02:39
Collect all URL's of subsites in a site collection
// Part 1.
// Collect all URL's of subsites in a site collection
function GetSubSiteUrls() {
// borrowed from Vadim Gremyachev: https://sharepoint.stackexchange.com/questions/137996/get-all-subsites-and-rootweb-of-a-site-collection-using-jsom#answer-137998
function enumWebs(propertiesToRetrieve, success, error) {
var ctx = new SP.ClientContext.get_current();
var rootWeb = ctx.get_site().get_rootWeb();
var result = [];
@samperrow
samperrow / Initialize Custom Form Updater
Last active March 16, 2019 02:34
Example of how to initialize the script.
// Example of how to initialize the script.
var init = function() {
var listName = 'Appointments';
var sourceFilePath = "https://example.sharepoint.com/assets";
var sourceFiles = [
{ filePath: sourceFilePath + '/NewForm.txt', title: 'NewForm' },
{ filePath: sourceFilePath + '/EditForm.txt', title: 'EditForm' },
{ filePath: sourceFilePath + '/DispForm.txt', title: 'DispForm' }
@samperrow
samperrow / Filter URL's and Collect List GUIDs
Created March 16, 2019 02:13
Filter down array of subsite URL's and return the ones that have the specified list.
/*
* 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;
@samperrow
samperrow / Create New Custom Forms
Last active March 16, 2019 02:32
Collect web part ID's, list GUIDs, and prepare target forms
/*
* Part 3.
* create new target forms for each target site.
* a) get source file content (from .txt files)
* b) get web part ID for each form
* c) create new form with the web part ID's, listGuids, and siteURL
* @param is an array of objects, each containing the subsite URL, list name, and the list GUID specified to that site.
*/
function GetListAndFormData(targetSites) {
@samperrow
samperrow / Initialize the Form Updating Process
Created March 16, 2019 02:21
Update the forms for each target site, one at a time.
/*
* Part 4.
* update the forms for each target site, one at a time.
* @param is an array of objects, each of which
*/
var UpdateForms = function(targetSites) {
var siteIndex = 0;
var formIndex = 0;