2017-10-17 58 views
0

我一直使用相同的腳本將約會導入到日曆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); 
} 
+0

這實際上是一個谷歌的問題。它再次運作。謝謝您的幫助!! – Mary

回答

0

你可以參考這個線程: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

附加參考:Google script google sheet to calendar TypeError: Cannot find function createEvent in object Calendar. (line 18, file "Code")

相關問題