当某人在Google表单中选中相关事件的复选框时,我想发送电子邮件邀请以进行日历事件。表单一次具有多个活动选项,我希望能够从同一表单提交中发送每个活动邀请。选择存储在同一单元格中,并用“,”分隔,这就是为什么我使用toString和Split函数的原因。
这是我到目前为止所拥有的,对效率低下表示歉意,因为我对此很陌生:
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);
}
}
感谢您的帮助。