Clear all events from a Calendar
Snippet
- See full code
- Leave a comment
- Create script from the snippet *See how to use scrviz for clone Apps Script project
/**
*
* @param {GoogleAppsScript.Calendar.Calendar} calendar
*/
function clearAllEvents_(calendar) {
const marks = [];
return calendar.getEvents(new Date(0), new Date()).map((event) => {
const id = event.getId();
if (!marks.includes(id))
if (event.isRecurringEvent()) {
calendar.getEventSeriesById(id).deleteEventSeries();
marks.push(id);
} else event.deleteEvent();
return id;
});
}
Run it
run.js/* global clearAllEvents_ */
/**
*
*/
function run() {
const calendar = CalendarApp.getCalendarById(
'1fq7choqdctaal2sk5i5du43qc@group.calendar.google.com'
);
console.log(clearAllEvents_(calendar));
}