Home > Enterprise >  Daily agenda for all Google owned calendars
Daily agenda for all Google owned calendars

Time:09-04

I'm trying to get daily agenda of the events from all my calendars (personal, holidays, specific tasks etc) sent in one email.

I use the following code for one specific calendar, but don't know how to add all other owned calendars in the same code, is that even possible?

function sendAllCalendarsAgenda() {
  var cal = CalendarApp.getOwnedCalendarById('[email protected]');
  var events = cal.getEventsForDay(new Date());
  var mailto = '[email protected]';

  if (events.length > 0) {
    var body = 'Google Calendar - Events'   'nn';
    var tz = Session.getScriptTimeZone();

    for (var i = 0; i < events.length; i  ) {
      body  = Utilities.formatDate(events[i].getStartTime(), tz, 'MM:dd HH:mm')   ' ~ ';
      body  = Utilities.formatDate(events[i].getEndTime(), tz, 'MM:dd HH:mm')   ' :';
      body  = events[i].getTitle()   'n';
    }

    MailApp.sendEmail(mailto, 'Google Calender - Summary', body);
  }
}

CodePudding user response:

Try this:

function sendAllCalendarsAgenda() {
  const cals = CalendarApp.getAllCalendars();
  let o = [];
    var body = 'Google Calendar - Events Summary'   '\n\n';
    cals.forEach(cal => {
      var events = cal.getEventsForDay(new Date());
      var mailto = '[email protected]';
      if (events.length > 0) {
        var tz = Session.getScriptTimeZone();
        for (var i = 0; i < events.length; i  ) {
          body  = event[i].getTitle();
          body  = Utilities.formatDate(events[i].getStartTime(), tz, 'MM:dd HH:mm')   ' ~ ';
          body  = Utilities.formatDate(events[i].getEndTime(), tz, 'MM:dd HH:mm')   ' :';
        }
        o.push(body);
      }
    });
    MailApp.sendEmail(mailto, 'Google Calendar - Summary', a.join('\n\n'));
}
  • Related