Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / 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 / 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 / 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 / spcalendarpro.js
Last active April 8, 2019 23:06
SP Calendar Pro- An ultra lightweight, dependency-free JavaScript library to easily manage SharePoint calendar events.
/*
* @name SPCalendarPro
* Version 1.3.2
* No dependencies!
* @description An ultra lightweight JavaScript library to easily manage SharePoint calendar events.
* @documentation https://sharepointhacks.com/sp-calendar-pro
* @author Sam Perrow sam.perrow399@gmail.com
*
* Copyright 2018 Sam Perrow (email : sam.perrow399@gmail.com)
* Licensed under the MIT license:
@samperrow
samperrow / getAllEvents.js
Created July 4, 2018 21:16
Collects all events (single and recurring) from a SharePoint calendar list.
// get recurring calendar events
var events = []; // this is the global variable I am using to store the events data.
function getCalendarEvents(listName, async) {
// set up the CAML query. returns single and recurring events by default, unless otherwise specified.
var camlQuery = "<query>" +
"<Query>" +
"<Where>" +
// get recurring calendar events
var events = []; // this is the global variable I am using to store the events data.
function getCalendarEvents(listName, asyn) {
// set up the CAML query. returns single and recurring events by default, unless otherwise specified.
var camlQuery = "<query>" +
"<Query>" +
"<Where>" +
@samperrow
samperrow / original XSL markup for datetime
Created June 19, 2018 22:11
Original XSL markup for UTC datetime
<xsl:value-of select=@EventDate/>
@samperrow
samperrow / Format default UTC datetimes
Last active June 19, 2018 22:29
Replaces the default UTC datetime stamps on SharePoint display forms with formatted datetimes.
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1037, 'yyyy-MM-dd hh:mm:ss')"/>