Skip to content

Instantly share code, notes, and snippets.

View phillypb's full-sized avatar

Phil Bainbridge phillypb

View GitHub Profile
/*
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');
/*
Loop through a folder of CSV files.
Capture tutor name (from file name) and code the file ID / Module Code / Group No with it in a JavaScript Object.
Collates/sorts all files together for each individual tutor.
End result is ability to loop through JavaScript Object and action CSV files
belonging to each tutor in-turn.
Collated data will look like this:
{Micky Mouse=[{fileId=1BRv0IhTxYxhsYbDN85DkpMqrTPyJHXyK, group=Grp 05.csv, moduleCode=CDE}, {moduleCode=CDE, fileId=1dmwVbPdwNQbOg9nfO98RD213QpKOLuqk, group=Grp 01.csv}], Jane Doe=[{group=Grp 04.csv, fileId=1z8O6jnm8INdZf9NWZBCoWTvB0zTEQDDe, moduleCode=ABC}, {moduleCode=ABC, fileId=1MnenQwueMKWssWlBOEaM8lcozB9ghYEn, group=Grp 03.csv}, {fileId=1-kh1Vp6It4LvVNSahUMkP529hu4-_es9, moduleCode=ABC, group=Grp 02.csv}]}
*/
/*
Loop through a folder of CSV files.
Capture tutor name (from file name) and file ID in a JavaScript Object.
Collates/sorts all files together for each individual tutor.
End result is ability to loop through JavaScript Object and action CSV files
belonging to each tutor in-turn.
Collated data will look like this:
{"Jane Doe":["1-kh1Vp6It4LvVNSahUMkP529hu4-_es9","1z8O6jnm8INdZf9NWZBCoWTvB0zTEQDDe","1MnenQwueMKWssWlBOEaM8lcozB9ghYEn"],"Micky Mouse":["1BRv0IhTxYxhsYbDN85DkpMqrTPyJHXyK","1dmwVbPdwNQbOg9nfO98RD213QpKOLuqk"]}
*/
/*
Sort through an array and remove any duplicate values.
Does not account for changes in case-sensitivity.
*/
function removeDuplicates() {
// array of duplicates
var rawArray = ['Dave', 'Jim', 'Dave', 'Nicky', 'Nicky', 'Bob', 'Bob', 'Bob'];