I am trying to use the vacation calendar app script but I only want to include all-day events, regardless of whether people are using a default event or an OOO event. There is a similar question here but this answer only works for default events and all OOO-type events are being filtered out
This type of event always returns that it is not all day, even when it is:
The Event class returned by Calendar.Events.list() does not appear to contain this information, but per the other thread I altered to retrieve a CalendarEvent object and it works correctly if the calendar event is a default event type. However, if the event is an outOfOffice event then everything returns as not all day, even when it is, which means none of my OOO events get added. Does anyone know how to get it to correctly read the OOO events for all-day vs timed?
The relevant code is this shouldImportEvent
function:
function shouldImportEvent(user, keyword, event) {
// Filters out events where the keyword did not appear in the summary
// (that is, the keyword appeared in a different field, and are thus
// is not likely to be relevant).
if (event.summary.toLowerCase().indexOf(keyword) < 0) {
return false;
}
// Only import events that are all day
let calEvent = CalendarApp.getCalendarById(user.getEmail()).getEventById(event.id)
if (!calEvent.isAllDayEvent()) {
// all outOfOffice events are returning here
return false;
}
if (!event.organizer || event.organizer.email == user.getEmail()) {
// If the user is the creator of the event, always imports it.
return true;
}
// Only imports events the user has accepted.
if (!event.attendees) return false;
let matching = event.attendees.filter(function(attendee) {
return attendee.self;
});
return matching.length > 0 && matching[0].responseStatus == 'accepted';
}
Lindsey Hanna SheHer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1