Skip to content Skip to sidebar Skip to footer

Google Apps Script: How To Check If A Calendar Event Has Been Marked As Deleted Manually

I've written a Google Apps Script which adds events kept in a spreadsheet to a google calendar. Each event stores the calendar event's ID so that it can update it if the event in t

Solution 1:

I have spent quite a time solving this and I cant udnerstand why there is no better way how to solve it, directly by CalendarApp. What you need is this:

var eventId = "5qif5n15v46c0jt5gq20a39dqu@google.com".split("@")[0];
if(Calendar.Events.get("yourCalendarId", eventId).status === "cancelled")
        CODE://what to do if event was deleted (manually)

Notes:

  1. As API v3.0 uses as eventid only the part before @, so you need to split (strip rest)
  2. You need Calendar API v3.0 first activate.

You will find more info about in this question: Checking a Google Calendar Event's Existence

Solution 2:

I found that the best way to do this is to check whether the event in question is included when asking the calendar for events during the time period of event in question:

varevent = calendar.getEventById(eventId);
var events = calendar.getEvents(event.getStartTime(),event.getEndTime());
var isEventDeleted = events.some((event) => event.getId() == eventId);

Methods used:

https://developers.google.com/apps-script/reference/calendar/calendar#getEventById(String)https://developers.google.com/apps-script/reference/calendar/calendar#geteventsstarttime,-endtimehttps://developers.google.com/apps-script/reference/calendar/calendar-event#getstarttimehttps://developers.google.com/apps-script/reference/calendar/calendar-event#getendtimehttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some

Solution 3:

Another solution would be to search only events that have not yet been deleted, which will cause deleted events to not be found.

let result = Calendar.Events.list(<Calendar_ID>, {showDeleted: false});

Solution 4:

I found the Simpler Way is check if the Return is null or Not. Null = event not found

https://developers.google.com/apps-script/reference/calendar/calendar#geteventbyidicalid

CalendarEvent — the event with the given ID, or null if the event doesn't exist or the user cannot access it.

Post a Comment for "Google Apps Script: How To Check If A Calendar Event Has Been Marked As Deleted Manually"