"All Day Event Calendar" Error

9 views
Skip to first unread message

C. Omar Kebbeh

unread,
11:47 AM (2 hours ago) 11:47 AM
to google-apps-sc...@googlegroups.com
Hi all,

Need help with this code. Some things have been redacted. Essentially, I would like to use Google Sheets content to create a calendar invite and then notify a team called DOC  (jaen...@nothing.gov')  that there is a new event added to the calendar. I'm getting the error below but don't know how to fix it. The program works. Calendar gets populated but then the below error pops up. Also, I would like  body += 'Date: ' + event.getAllDayStartDate().toDateString() + '\n'; // Get start date of all-day event    to pick up both the start and end dates but for now it is only picking up start date. I also would like to pick up columns G and I from the spreadsheet and add them to email that will be sent out. Here is the file (https://docs.google.com/spreadsheets/d/1jCp8j3pWmVYGtLAVJK1j6ynAevNRzSAzQsK-7Jh97xM/edit?gid=869555125#gid=869555125). 

Thanks,
Omar 

image.png


function twoMissions(){
  // get Calendar ID
  let sheet = SpreadsheetApp.getActiveSheet()
  let id = SpreadsheetApp.getActive().getRangeByName("calendarID").getValue()
 
  // get Event data...the filter allows us to only get rows that contain data, and to exclude the checkbox in the filter
  let events = SpreadsheetApp.getActive().getRangeByName("EventList").getValues().filter(array => array.slice(0, -1).some(value => value !== ''));

  //single day event with just title and date
 events.forEach( function(e, index){
    if(!e[8]){
      let event = CalendarApp.getCalendarById(id)
      .createAllDayEvent(
        e[0],
        e[1],
        e[10],
        {description: e[3],
        location:e[4],
        })
      let newIndex = index+8;
      sheet.getRange("J"+ newIndex).setValue(true);

      // Send email notification
      sendNotificationEmail(event, 'jaen...@nothing.gov');
    }
  })
}

function sendNotificationEmail(event, recipient) {
  let subject = 'New Event Added to Program Cycle and Mission Events Calendar';
  let body = 'Dear DOC Team - A new event has been added to the Cycle and Upcoming Events Calendar - See Mission Calendar (https://docs.google.com/spreadsheets/d/1SNPG8oVmG4gXPnDGEcLXn33qzGWtwEFofaoOukFwRD4/edit?gid=869555125#gid=8695551) for details. :\n\n';
  body += 'Title: ' + event.getTitle() + '\n';
  body += 'Date: ' + event.getAllDayStartDate().toDateString() + '\n'; // Get start date of all-day event
  body += 'Description: ' + event.getDescription() + '\n';
  body += 'Location: ' + event.getLocation() + '\n';
  body += 'Guests: ' + event.getGuestList().join(', ') + '\n'; // Get list of guests

  MailApp.sendEmail(recipient, subject, body);
}




image.png
Reply all
Reply to author
Forward
0 new messages