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();
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchEvents() { | |
// date to search for Events on | |
var date = new Date('Sat Jul 27 2019'); | |
Logger.log('Date to search is: ' + date); | |
// Id of the Calendar to be searched | |
var calendarId = 'youremail@example.com' | |
// get the Calendar | |
var calendar = CalendarApp.getCalendarById(calendarId); | |
// get a list of the Events for the given date | |
var allEvents = calendar.getEventsForDay(date); | |
// loop through each event to extract information *********************************** | |
for (var i=0; i<allEvents.length; i++) { | |
var event = allEvents[i]; | |
var eventTitle = event.getTitle(); | |
Logger.log('Event Title is: ' + eventTitle); | |
var eventId = event.getId(); | |
Logger.log('Event Id is: ' + eventId); | |
} | |
// end of loop through each event to extract information **************************** | |
} |
Hi! Can I use a script to search/ filter for calendar events by colour?
ReplyDeleteHi
DeleteYes 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