简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM