google-apps-scriptgoogle-calendar-recurring-eventsgsuite-addons

Get recurrence of CalendarEvent in G-Suite Addon


I'm working on a Google Calendar addon that synchronizes event data with an external service. It's easy to get data like title, description, dates etc. of an event and I can even check wether it's a recurring event or not with event.isRecurringEvent().

What I can't seem to find out is how to get the recurrence rule(s) for a specific event. Is this even possible? Neither https://developers.google.com/apps-script/reference/calendar/calendar-event nor https://developers.google.com/apps-script/reference/calendar/calendar-event-series have something like getRecurrenceRule()

Thanks for any help!


Solution

  • If I understand you correctly, you have a CalendarEvent in Google Apps Script and you want to get its recurrence.

    Since, as you said, there is not a method like getRecurrenceRule(), you will have to activate the Advanced Calendar Service and call Events: get to get information on the recurrence of the event. If event is your CalendarEvent, you can retrieve the information on the recurrence by doing the following:

    eventId = event.getId().split("@")[0];
    var eventFromAPI = Calendar.Events.get(calId, eventId);
    var recurrence = eventFromAPI["recurrence"];
    return recurrence;
    

    Notes:

    Reference:

    I hope this is of any help.