Your time is important. In this example we'll show you how you can build a Calendar to Coda sync so you can do the following:
Pull stats out of your calendar
How much time are you spending in meetings? What types of meetings?
Who you are spending time with?
Make the most of the time you and your team spend in meetings by adding meaningful metadata:
Goals
Notes per meeting
Sentiment indicator
Follow ups
What you'll learn
How to access Google Calendar events from Google Apps Script
How to write calendar data into rows in a Coda table
Instructions
1. Setup
Here's a table you can use to store your events. We'll be using column names instead of IDs for simplicity, so be careful not to rename any columns, or your script will start failing (and you'll get failure notifications from Google).
ⓘ If you copy this table outside of this doc, you'll have to set the formula on the Day column to [Start Time].DateTimeTruncate('day') .
ⓘ You'll have to replace you@example.com with your desired calendar's ID. For your personal calendar, this is usually your email address. For other calendars, you can go to
, go into "Settings" via the hover menu for the calendar you're interested in within the left sidebar, and then use the "Calendar ID" that's in the "Integrate calendar" section.
CodaAPI.authenticate('abcd1234-efgh-5678-ijkl-1234mnop5678'); // Replace with your token.
// Configure as needed below.
GOOGLE_CALENDAR_NAME = 'you@example.com';
DAYS_TO_SYNC_BEFORE_TODAY = 14;
DAYS_TO_SYNC_AFTER_TODAY = 14;
CALENDAR_DOC_ID = 'TO UPDATE';
CALENDAR_TABLE_NAME = 'My Calendar';
/**
* How do you want deleted events and events outside the time range specified above handled?
*
* - 'remove_deleted' (default): keep events in Coda within the range specified. Cancelled events
* will be removed, while events that fall out out of the sync window will be kept.
*
* - 'keep_all': never delete any rows in Coda - as soon as an event is saved, it will never
* be deleted (but will still be updated).
*
* - 'keep_synced': keep events in Coda that are only within the range specified. Calendar events in Coda
* for cancelled events and any events outside of the sync window will be deleted.
*/
EVENT_DELETE_BEHAVIOR = 'keep_synced';
/** Run me! (Depending on how many events you have, this may take a couple minutes, so hang tight.) */
function syncGoogleCalendarEvents() {
// Get the date range we want to sync.
var syncRange = getDateRange(new Date(), DAYS_TO_SYNC_BEFORE_TODAY, DAYS_TO_SYNC_AFTER_TODAY);
// Get calendar data from Google Calendar.
var events = getCalendarData(GOOGLE_CALENDAR_NAME, syncRange);