Reputation: 2788
If I get all of the events from a Google calendar using Apps Script, how can I tell if the event is recurring or not?
For example I can get an array of events using:
function test() {
var startTime = new Date(2019, 8, 1)
var endTime = new Date()
var c = CalendarApp.getAllCalendars()[0]
var a = c.getEvents(startTime, endTime)
a.forEach(function(e) {
var id = e.getId()
Logger.log(id)
var b = c.getEventSeriesById(id)
if (b !== null) {
Logger.log('got series')
}
})
return
} // test()
But getEventSeriesById() returns an event series regardless of whether the event has one or not.
Upvotes: 1
Views: 282
Reputation: 2788
I eventually resorted to using the Advanced Calendar service which has a "recurrence" property in the event object only for recurring events:
function test2() {
var events = Calendar.Events.list(CALENDAR_NAME).items
events.forEach(function(event) {
if (event.hasOwnProperty('recurrence')) {
Logger.log('Recurring event: ' + event.id)
} else {
Logger.log('None Recurring event: ' + event.id)
}
})
}
Upvotes: 3