防止在某个时间范围内从Google表单复制到Google日历

时间:2019-07-19 04:06:38

标签: google-apps-script google-sheets google-calendar-api google-form

我有这套预订系统代码,我从Google查找了这些代码,并更改了一些代码以满足我的需求。从表单到日历的详细信息获取过程成功。但是然后,我遇到了一个问题,我不想让我的用户在预订时间范围内进行预订。

例如,

USER1已预订,星期一,上午8点至上午10点。如果其他用户想在上午8点至上午10点之间进行预订,则预订将被拒绝,并且不会反映在日历上。如果有一个脚本可以将预订失败的电子邮件发送给用户,那就更好了。

function onFormSubmit() {
createCalendarEvent();
}

function createCalendarEvent() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var calendar = CalendarApp.getCalendarById('calendar ID');

  var startRow = 2;  // First row of data to process - 2 exempts my header row
  var numRows = sheet.getLastRow();   // Number of rows to process
  var numColumns = sheet.getLastColumn();

  var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns); 
  var data = dataRange.getValues();

  var complete = "Done";

  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var date = new Date(row[1]);  //start datetime
    var rDate = new Date(row[2]); //end datetime
    var event = row[3]; //event
    var venue = row[4];  //Venue 
    var user = row[5]; //user
    var eventID = row[6]; //event marked Done

    if (eventID != complete) {
      var currentCell = sheet.getRange(startRow + i, numColumns);
      calendar.createEvent(subject, date, rDate, {
        description: 'Booked by: ' + user
      });
     currentCell.setValue(complete);
    }
  }
}

0 个答案:

没有答案