Skip to content

Instantly share code, notes, and snippets.

@glenndevenish
Created February 19, 2018 10:01
Show Gist options
  • Save glenndevenish/7d8ebc548da738c13465959cbed83b60 to your computer and use it in GitHub Desktop.
Save glenndevenish/7d8ebc548da738c13465959cbed83b60 to your computer and use it in GitHub Desktop.
Google Forms to Google Calendar integration
/*
From the Google Form, go to script editor. Enter this code.
You will need:
Calendar ID
Form ID
License:
Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
No warranty — If things go wrong, it's your fault.
*/
// Get your calendar id and enter it here:
var calendar = CalendarApp.getOwnedCalendarById('your-calendar-id@group.calendar.google.com');
// Get your form id and enter it here:
var form = FormApp.openById('your-form-id');
// set FormToCalendar to run on form submit
function FormToCalendar() {
var formResponses = form.getResponses();
var lastResponse = formResponses.length - 1; // formResponses is all responses ever, so we only want the latest one.
var formData = formResponses[lastResponse];
var items = form.getItems();
// Copy below line and increment items[] value for each form response (they are in the same order as the form)
var eventName = formData.getResponseForItem(items[0]).getResponse();
var eventDate = new Date(formData.getResponseForItem(items[1].getResponse());
var eventDescription = formData.getResponseForItem(items[2]).getResponse();
// Create time-based event
var event = calendar.createEvent(
eventName, // Event Name
new Date(eventDate.setHours(9, 0)), // Event start time (setHours takes (hours, minutes, seconds))
new Date(eventDate.setHours(9, 30)) // Event end
);
event.setDescription(eventDescription);
// Create all-day event
var event = calendar.createAllDayEvent(eventName, eventDate);
event.setDescription(eventDescription);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment