脚本尝试将全天事件导入到日历时的错误代码
问题描述:
我一直使用相同的脚本将约会导入到日历2年,没有任何问题。今天突然间,我得到一个读取TypeError的错误代码:在对象Calendar中找不到函数createAllDayEvent。 (第35行,文件“代码”)脚本尝试将全天事件导入到日历时的错误代码
为什么会发生这种情况?我们使用这个脚本安排公司交付,所以我真的需要它的工作。任何帮助将不胜感激!!
这是我一直在使用脚本...
function importCalendar() {
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 1; // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var data = range.getValues();
var calId = "CALENDAR ID HERE";
var cal = CalendarApp.getCalendarById(calId);
for (i=0; i<data.length; i++) {
if (i < headerRows) continue; // Skip header row(s)
var row = data[i];
var startDate = row[3]; // Fourth column
var title = row[1]; // Second column
var location = row[2];
var description = row[4];
var id = row[6]; // Seventh column == eventId
var advancedArgs ={description: description, location: location};
// Check if event already exists, update it if it does
try {
var event = cal.getEventSeriesById(id);
}
catch (e) {
// do nothing - we just want to avoid the exception when event doesn't exist
}
if (!event) {
//cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description:desc,location:loc});
var newEvent = cal.createAllDayEvent(title, new Date(startDate), advancedArgs).getId(); This is the row with the error.
row[6] = newEvent; // Update the data array with event ID
}
else {
Utilities.sleep(5000);
event.setTitle(title);
event.setDescription(description);
event.setLocation(location);
// event.setTime(tstart, tstop); // cannot setTime on eventSeries.
// ... but we CAN set recurrence!
var recurrence = CalendarApp.newRecurrence().addDailyRule().times(1);
event.setRecurrence(recurrence, new Date(startDate));
}
debugger;
}
// Record all event IDs to spreadsheet
range.setValues(data);
}
答
你可以参考这个线程:Cannot find function createEvent (or createAllDayEvent) in object Calendar. (Google Spreadsheet App)。确保你的startDate
变量具有正确的格式。
if you are not sure about the 'date' variable being actually a date you could use
cal.createAllDayEvent(title, new Date(date), {description:desc,location:loc});
that said, it is quite easy to check with the logger
Logger.log(date)
should return a date value in the form
Tue Sep 18 03:00:00 PDT 2012
这实际上是一个谷歌的问题。它再次运作。谢谢您的帮助!! – Mary