Create Calendar Events

CalendarApp lets you create events on your Google Calendar (or any calendar you own) directly from a script. You can set the title, date, time, duration, description, location, and more.

Creating a Simple Timed Event

function createFollowUpCall() { var calendar = CalendarApp.getDefaultCalendar(); var start = new Date("2024-03-25T10:00:00"); var end = new Date("2024-03-25T10:30:00"); var event = calendar.createEvent( "Follow-up Call – Mark Chen (Enterprise Plan)", start, end ); Logger.log("Event created: " + event.getTitle() + " | ID: " + event.getId()); }

Creating an Event with a Description and Location

function createOnboardingSession() { var calendar = CalendarApp.getDefaultCalendar(); var start = new Date("2024-03-26T14:00:00"); var end = new Date("2024-03-26T15:00:00"); var event = calendar.createEvent( "Onboarding Session – Sarah Johnson", start, end, { description: "Pro Plan onboarding walkthrough.\nCustomer: Sarah Johnson ([email protected])\nAccount Manager: Alex Martinez", location: "Google Meet", sendInvites: true } ); Logger.log("Onboarding event created: " + event.getTitle()); }

Creating an All-Day Event

function createContractSignedEvent() { var calendar = CalendarApp.getDefaultCalendar(); var date = new Date("2024-03-15"); var event = calendar.createAllDayEvent( "Contract Signed – Sarah Johnson (Pro Plan)", date, { description: "Sarah Johnson signed the Pro Plan contract. Region: North. Rep: Alex Martinez." } ); Logger.log("All-day event created: " + event.getTitle()); }

Auto-Creating Follow-Up Events from Sheet Data

This example reads all In Progress deals from the Sales Tracker and creates a 30-minute follow-up call event scheduled 2 days from today for each:

function createFollowUpEventsFromSheet() { var sheet = SpreadsheetApp .getActiveSpreadsheet() .getSheetByName("Sales Tracker"); var data = sheet.getRange(2, 1, sheet.getLastRow() - 1, 8).getValues(); // Columns: [Customer Name, Email, Product, Amount, Region, Sales Rep, Status, Date] var calendar = CalendarApp.getDefaultCalendar(); var twoDaysFromNow = new Date(); twoDaysFromNow.setDate(twoDaysFromNow.getDate() + 2); data.forEach(function(row) { var customerName = row[0]; var product = row[2]; var salesRep = row[5]; var status = row[6]; if (status !== "In Progress") return; var start = new Date(twoDaysFromNow); start.setHours(10, 0, 0, 0); var end = new Date(start.getTime() + 30 * 60 * 1000); // 30 minutes var event = calendar.createEvent( "Follow-up Call – " + customerName + " (" + product + ")", start, end, { description: "Follow-up for " + product + " evaluation.\nCustomer: " + customerName + "\nSales Rep: " + salesRep } ); Logger.log("Event created for: " + customerName + " | " + event.getId()); }); }

With the sample data, a follow-up call is created for Mark Chen (Enterprise Plan, In Progress). Sarah and Lisa are skipped.

Setting a Reminder on an Event

function createEventWithReminder() { var calendar = CalendarApp.getDefaultCalendar(); var start = new Date("2024-03-27T09:00:00"); var end = new Date("2024-03-27T09:30:00"); var event = calendar.createEvent("Sales Team Standup", start, end); event.addEmailReminder(30); // Email 30 minutes before event.addPopupReminder(10); // Popup 10 minutes before Logger.log("Event with reminders created: " + event.getTitle()); }