Skip to content

Instantly share code, notes, and snippets.

@matsubo
Created April 23, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsubo/06deb0519da53cb8f95c9bc878a518ff to your computer and use it in GitHub Desktop.
Save matsubo/06deb0519da53cb8f95c9bc878a518ff to your computer and use it in GitHub Desktop.
function scheduleShifts() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarId = spreadsheet.getRange("A2").getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);
var signups = spreadsheet.getRange("A5:D12").getValues();
for ( x=0; x < signups.length; x++) {
var shift = signups[x];
var startTime = new Date(shift[0]);
var endTime = new Date(shift[1]);
var title = shift[2];
var options = {
description: shift[3]
};
console.info(shift);
eventCal.createEvent(title, startTime, endTime, options);
}
}
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Sync to Calendar')
.addItem('Schedule shifts', 'scheduleShifts')
.addToUi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment