I would like to send email invites for calendar events when someone selects the checkbox for the relevant event in a Google form. The form has multiple options for events at one time, and I'd like to be able to send every event invite from the same form submission. The selections are stored in the same cell and separated by ", " which is why I'm using the toString and Split functions.
Here is what I have so far, apologies for inefficiency as I am quite new to this:
function onFormSubmit(e) {
var user = {name: e.namedValues['Name'][0], email: e.namedValues['Email Address'][0]};
var response = [];
var responseValues = SpreadsheetApp.openById('sheet_Id').getSheetByName('Form Responses').getDataRange().getValues();
var responseArray = []; // array for holding spreadsheet converted to String
for (var k = 0; k < responseValues.length; k++){
responseArray.push(toString(responseValues[k]).split(", "));
}
var eventValues = SpreadsheetApp.openById('sheet_Id').getSheetByName('Event Times').getDataRange().getValues();
// Search for event names within "Event Times" sheet. If the response includes an event name from "Event Times" sheet, log that event ID from the sheet
for(var i = 0; i < responseArray.length; i++){
for(var j = 0; j < eventValues.length; j++){
if(responseArray[i] == eventValues[j]) {
response.push(eventValues[j+5]); //the event ID is 5 cells to the right of the event name in the "Event Times" sheet
}
}
}
sendInvites_(user, response);
}
function sendInvites_(user, response) {
var cal = CalendarApp.getCalendarById('calendar_Id');
for (var i = 0; i < response.length; i++) {
cal.getEventById(response[i]).addGuest(user.email);
}
}
Thanks for the help.