Skip to content

Instantly share code, notes, and snippets.

View phillypb's full-sized avatar

Phil Bainbridge phillypb

View GitHub Profile
/**
* Function to check if date in spreadsheet is less than todays date.
* If so then autofill formulas down a row.
* Run via daily Trigger.
*
* @OnlyCurrentDoc
*/
function autofill() {
function getFormData(e) {
// get all Form responses
var formValues = e.namedValues;
// get response to specific question
var pizzaTopping = formValues["Favourite Pizza Topping"][0];
console.log("pizzaTopping is: " + pizzaTopping);
/*
Function to sort through an array of duplicates, to then create a new array of
unique values.
*/
function sortArray() {
// array to sort
var messyArray = ['A', 'B', 'A', 'C', 'B', 'B', 'B'];
/*
Some Global Variables to make it easier to keep a track of changing column
positions, etc.
*/
// 'Folder Name' column number
var folderNameCol = 1;
// 'Folder Link' column number
var folderLinkCol = 2;
function saveToProperties() {
// save to User Properties in one go
var userProperties = PropertiesService.getUserProperties();
var newProperties = {
sourceFolderId: '123',
destinationFolderId: '456',
};
userProperties.setProperties(newProperties);
/*
Some Global Variables to make it easier to keep a track of changing column
positions, etc.
*/
// 'File Link' column number
var fileLinkCol = 2;
// Maximum runtime of script in minutes to prevent timeout (5 minutes)
var maxRuntime = 5 * 60 * 1000;
/*
Create menu item to run script from spreadsheet.
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Create Doc')
.addItem('Create Doc', 'getSpreadsheetData')
.addToUi();
/*
Global Variables that may need to be tweaked and are easier to access by placing here.
*/
// Maximum runtime of script in minutes to prevent timeout (5 minutes)
var maxRuntime = 5 * 60 * 1000;
/*
function switchActiveView() {
// get spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get cell range in destination sheet that the view will be switched to
var range = ss.getRange('Sheet2!A1');
// activate cell range so cursor moves to that position and changes the current view
range.activateAsCurrentCell();
/*
Search a date range in Google Calendar for events matching a given string
and then delete them.
*/
function deleteEvents() {
// start date (MM/DD/YYYY)
var startDate = new Date('11/01/2022');