Thursday 25 July 2019

Search Google Calendar for event details

The following Google Apps Script is designed to search through a given date on Google Calendar, look through the events and then extract their Title & Id. The script is standalone so it only logs the output but you could copy it into a Google Sheet and write the data into the spreadsheet.

The 'CalendarApp' is used to perform the task and we start by getting hold of the relevant calendar.
var calendar = CalendarApp.getCalendarById(calendarId);
Next we get an array of the events for our given date.
var allEvents = calendar.getEventsForDay(date);
As we now have an array we need to loop through each returned event and extract the Title & Id.
for (var i=0; i<allEvents.length; i++) {
    var event = allEvents[i];
    var eventTitle = event.getTitle();
    var eventId = event.getId();
}

Search for events on date.gs

2 comments:

  1. Hi! Can I use a script to search/ filter for calendar events by colour?

    ReplyDelete
    Replies
    1. Hi

      Yes it looks like there is a Color option in Apps Script (https://developers.google.com/apps-script/reference/calendar/calendar-event#getcolor).

      Kind regards
      Phil

      Delete