2

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!

Pelle
  • 370
  • 2
  • 11
  • What about [getEventSeries()](https://developers.google.com/apps-script/reference/calendar/calendar-event#getEventSeries())? – Casper Feb 07 '20 at 08:55
  • @Casper, that returns an array of events (https://developers.google.com/apps-script/reference/calendar/calendar-event-series.html). No getRecurrenceRule or similar either – Pelle Feb 07 '20 at 09:04
  • 1
    Perhaps try with API as suggested in [this question](https://stackoverflow.com/questions/32770235/how-to-read-calendar-event-recurrence-settings-using-google-apps-script) – Casper Feb 07 '20 at 09:09
  • Cheers @Casper! I'll give that a try! Thanks! – Pelle Feb 07 '20 at 09:39

1 Answers1

3

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:

  • I'm using split to remove the characters after @ of the string returned by event.getId(), because it appends @google.com.
  • The recurrence is a "list of RRULE, EXRULE, RDATE and EXDATE lines for a recurring event, as specified in RFC5545". Even though this has information of the recurrence of the event, it's not an instance of the Apps Script class RecurrenceRule. As far as I know, there is no way to return that.

Reference:

I hope this is of any help.

Community
  • 1
  • 1
Iamblichus
  • 18,540
  • 2
  • 11
  • 27