Calendar Reservation Project

My new project uses a data submitted to a Google Form to create events on a calendar. The Google Form asks for the person’s name, reason for the visit and allows them to select the day and time for their appointment. The code uses an on Form submission trigger, it takes the day and time of the requested appointment and adds it to a specified calendar. The person’s name is used as the title for the new event.

I will be posting a video tutorial for this project shortly.

[code]
// Calendar Reservation Project
// Kurt Kaiser, 2017
// All rights reserved

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();

// Calendar to output requests
var calendar = CalendarApp.getCalendarById(‘e6i9tfp012mt4m5ic81v9lisp0@group.calendar.google.com’);

// Creates an object from the last form submission
function getSubmission(){
this.timestamp = sheet.getRange(lastRow, 1).getValue();
this.name = sheet.getRange(lastRow, 2).getValue();
this.reason = sheet.getRange(lastRow, 3).getValue();
this.date = new Date(sheet.getRange(lastRow, 4).getValue());
this.time = sheet.getRange(lastRow, 5).getValue();
return this;
}

// Creates a calendar event using the submitted data
function updateCalendar(request){
request.date.setHours(request.time.getHours());
request.date.setMinutes(request.time.getMinutes());
var endTime = new Date(request.date);
endTime.setHours(endTime.getHours() + 1);
var event = calendar.createEvent(
request.name,
request.date,
endTime
)
}

 

// ————–Main————–
function main(){
var request = getSubmission();
updateCalendar(request);
}

 

 

[/code]