我已经阅读了SO和其他地方的许多文章,以了解如何防止脚本在每次运行时继续添加重复的日历事件。到目前为止,我一直没有成功停止重复。
这是我的代码:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "Push to Calendar", functionName: "sendCalendarEvents"} ];
ss.addMenu("Custom Menu", menuEntries);
}
function sendCalendarEvents() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarId = spreadsheet.getRange('G1').getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);
var lastRow = spreadsheet.getLastRow();
var count = spreadsheet.getRange("A3:E"+lastRow+"").getValues();//five columns
var minutesBefore = 462
for (x=0; x<count.length; x++) {
var row = count[x];
var title = row[0];
var startTime = row[1];
var endTime = row[2];
var guests = row[3];
var description = row[4];
var location = row[5];
var id = row[7];no row[7]
var options = {
'location': location,
'description': description,
'guests':guests +',',
'sendInvites': 'True',
}
if(!id) {
var event = eventCal.createAllDayEvent(title, startTime, options);
var newEventId = event.getId();
spreadsheet.getRange(x+3,7).setValue('yes');
spreadsheet.getRange(x+3,8).setValue(newEventId);
event.addEmailReminder(minutesBefore);
Logger.log('Event ID: ' + event.getId());
这是我的电子表格(带有“测试”数据)
我也尝试过'if'语句的变体(就像if(row [x] [7]!='是')...创建事件),但这也没有用。
有帮助吗?解决重复的问题之后,我希望能够让用户在电子表格中编辑事件的日期或标题等,并删除现有事件,然后再设置新事件(具有更新的标题/日期)创建...如果可能的话。
感谢您提供的任何帮助!
var count = spreadsheet.getRange("A3:E"+lastRow+"").getValues();//only five columns in your data
var minutesBefore = 462
for (x=0; x<count.length; x++) {
var row = count[x];
var title = row[0];
var startTime = row[1];
var endTime = row[2];
var guests = row[3];
var description = row[4];
var location = row[5];
var id = row[7];//Problem is right here...there is no row[7];