防止来自 Apps 脚本的重复日历事件

Prevent duplicate calendar events from Apps Script

我已经阅读了 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());

这是我的电子表格(包含 'test' 数据)

我还尝试了 'if' 语句的变体(比如 if (row[x][7] != 'yes')...创建事件) 但这也没有用。

有什么帮助吗?解决重复问题后,我希望能够让用户编辑电子表格中事件的日期或标题等,并删除现有事件,然后删除新事件(更新 title/date ) 被创建...如果可能的话。

感谢您提供的任何帮助!

您的数据中只有五列。没有行[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];