← All Apps Scripts templates
/
Create event with Google Calendar

Create event with Google Calendar

To use this script, follow these steps:

  1. Open a Google Sheet that you want to use to trigger the creation of the calendar event.
  2. Go to the “Tools” menu and select “Script editor.”
  3. Copy and paste the code provided into the script editor.
  4. Modify the calendarId, eventTitle, startTime, endTime, and eventDescription variables to match your desired settings.
  5. Save the script and close the script editor.
  6. In the Google Sheet, add a trigger to run the createCalendarEvent function on a specified schedule or event trigger.

When the createCalendarEvent function is triggered, it will create a new calendar event in the specified calendar with the specified details. The event ID will be logged to the console, which can be useful for tracking and referencing the event in future script executions.

Paste this code below in Apps Script:


function createCalendarEvent() {
  var calendarId = 'primary'; // ID of the calendar to create the event in
  var eventTitle = 'Example Event'; // Title of the new event
  var startTime = new Date('2023-04-05T09:00:00-07:00'); // Start time of the event
  var endTime = new Date('2023-04-05T10:00:00-07:00'); // End time of the event
  var eventDescription = 'This is an example event.'; // Description of the new event
  
  var event = CalendarApp.getCalendarById(calendarId).createEvent(eventTitle, startTime, endTime, {
    description: eventDescription
  });
  
  // Log the event ID to the console
  Logger.log('Event ID: ' + event.getId());
}

Reach us if the process is unclear or if the script is outdated
Apps Scripts template

Create event with Google Calendar

Last updated
4/4/2023
Built by
Avatar Placeholder
internal

This script creates a new calendar event in Google Calendar with the specified title, start time, end time, and description. The event is created in the calendar specified by the calendarId variable.

Similar Apps Script for

Google Calendar

in Google Sheets

No similar items yet.