运输申请表日期/时间问题

时间:2019-01-14 19:53:37

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

我们有一个运输申请表,用于分配车辆。它还会填充一个日历,以跟上哪一天正在使用哪些车辆。问题是,如果“返回详细信息”的时间和日期不在“出发详细信息”之后,则会引发错误,并且日历项创建功能将无法运行。

例如对于某些人来说,凌晨12点是一个问题。他们可能会...离开1/20 4pm,返回1/20 12am。实际上是在出发前。其他时候,他们只是匆忙输入错误的日期。

我想检查提交的那部分内容,如果发回给请求者的电子邮件中的发送和编辑url链接出错,并提供修复说明。

任何帮助,将不胜感激。

function createCalEvent(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); 
var columnIndex = headers[0].indexOf(calendarColumnName);
var data = sheet.getDataRange().getValues();
var form = FormApp.openById(formURL);
var emailAddress = "transportation@.net";
var myCal = CalendarApp.getCalendarById('transportation@.net');
for(var i = startRow-1; i < data.length; i++) {
if(data[i][0] != '' && data[i][columnIndex] == '') {
  var timestamp = Utilities.formatDate(data[i][0], 'CST', 'MMMM dd, yyyy h:mm a');
  var staffName = data[i][1];
  var departureDate = Utilities.formatDate(data[i][2],'CST', "EEEE, MMMM dd, yyyy");
  var departureTime = Utilities.formatDate(data[i][3], 'CST', "h:mm a");
  var returnDate = Utilities.formatDate(data[i][4],'CST', "EEEE, MMMM dd, yyyy");
  var returnTime = Utilities.formatDate(data[i][5],'CST', "h:mm a");
  var destination = data[i][6];
  var groupAttending = data[i][7];
  var reasonForTrip = data[i][8];
  var teacherInCharge = data[i][9];
  var specialRequest = data[i][10];
  var vehicleOneAssigned = data[i][11];
  var vehicleTwoAssigned = data[i][12];
  var originalEmail = data[i][13];
  var numberOfPassengers = data[i][14];
  var requestorEmailAddress = data[i][15];
  var pdfUrlLink = data[i][40];
  var editURL = data[i][41];
  if(pdfUrlLink != ''){

  var title = staffName + '-' + destination + '-' + vehicleOneAssigned;
  var descriptionList = 'Group Attending: ' + groupAttending + '<br> Number of Passengers: ' + numberOfPassengers + '<br> Reason For Trip: ' + reasonForTrip + '<br> Teacher In Charge: ' + teacherInCharge + '<br> Special Request: ' + specialRequest + '<br> Request Link: ' + pdfUrlLink;
  var event = myCal.createEvent(title,
                            new Date(departureDate + ' ' + departureTime),
                            new Date(returnDate + ' ' + returnTime),
                                  {description: descriptionList});

    var eventID = event.getId();
    Logger.log('Calendar Calendar Event ID: ' + eventID);
    sheet.getRange(i+1, columnIndex+1).setValue(eventID);

      }
    }
  }
}

0 个答案:

没有答案