Skip to content

Instantly share code, notes, and snippets.

@medvedev
Created January 18, 2023 22:09
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 medvedev/b67eedc5c0303c8eee6555aab5ee857c to your computer and use it in GitHub Desktop.
Save medvedev/b67eedc5c0303c8eee6555aab5ee857c to your computer and use it in GitHub Desktop.
Googla App Script: Automatically invite to Calendar event based on Google Form data
// Code below looks a bit complicated for suc a simple action
// It's purpose is to add a guest to an event AND send email notification to a new guest.
// If email notification is optional, you can use simple apporach with CalendarApp
// Trigger type for the script should be "On Form submit"
// If it's your primary google calendar, use your email as ID
const calendarId = 'john.smith@gmail.com'
// How to get event ID:
// 1. Open event editor in Calendar Web UI
// 2. Base64 decode part or URL after "...eventedit/"
// 3. Use first string from the output as the eventId below
const eventId = 'xxxxxxxxxxxxx'
// Email column number in the form responses Google Sheet
const emailColumnId = 2
function addEventGuests() {
var sheet = SpreadsheetApp.getActiveSheet()
var email = sheet.getDataRange().getCell(sheet.getLastRow(), emailColumnId).getValue();
var event = Calendar.Events.get(calendarId, eventId);
if(event.attendees) {
event.attendees.push({
email: email
});
} else {
event.attendees = new Array({email: email});
}
event = Calendar.Events.patch(event, calendarId, eventId, {
sendNotifications: true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment