Search code examples
google-apps-scriptgoogle-calendar-api

Send calendar event invites


everyone. I am a beginner to this. Could you please help me add a code or where to add a code if I want to send and invites for each row. I already have a code, I want the invite code to be inline with my existing code. Thank you so much!!

I already have this code but I dont know what code to add to auto send an invites

Function createCalendarEvents(){
Let AgendaCalendar = CalendarApp.getCalendarByID("calendarid");
Let sheet = SpreadsheetApp.getActiveSheet();

Let schedule = sheet.getDataRange().getavalues();
Schedule.firEach(function(entry) {

AgendaCalendar.createEvent(entry[0], entry[1], entry [2]);

})
}

Solution

  • Try something like this. You did not specify guest emails so I just guessed

    function createCalendarEvents() {
      let cal = CalendarApp.getCalendarByID("calendarid");
      let sheet = SpreadsheetApp.getActiveSheet();
      let vs = sheet.getDataRange().getValues();
      vs.forEach(r => {
        let ev = cal.createEvent(r[0], r[1], r[2]);
        ev.addGuest(r[4]);//or whatever column is the guest email
      }); 
    }
    

    You obviously did not test your function so neither did I. It will probably require some debugging on your part