2012-06-29 36 views
0

不能調用未定義的方法「createEvent」在我的劇本和功能的下半年,我不斷收到這不能調用方法的錯誤,我不知道爲什麼。我完全模仿了模板腳本,但我不確定它爲什麼不調用該方法。時出錯:類型錯誤:通過谷歌腳本

任何有識之士將不勝感激。

謝謝。

function createEvents(e){ 

//Get the active application 
var app = UiApp.getActiveApplication(); 

try{ 
    //get the entries; 
    var eventDate = e.parameter.eventDate; 
var eventPeople = e.parameter.eventPeople; 
var eventCompany = e.parameter.eventCompany; 
var eventName = e.parameter.eventName; 
var eventTime = e.parameter.eventTime; 
var eventPhone = e.parameter.eventPhone; 
var eventEmail = e.parameter.eventEmail; 
var eventTaken = e.parameter.eventTaken; 


//Get the calendar 
var cal = CalendarApp.getCalendarsByName('Phoenix Reservations')[0];//Change the calendar name 
var eventStartTime = eventDate; 
//End time is calculated by adding an hour in the event start time 
var eventEndTime = new Date(eventDate.valueOf()+60*60*1000); 
//Create the events 
cal.createEvent(eventPeople,eventCompany,eventName,eventTime,eventPhone,eventEmail,eventTaken); 

//Log the entries in a spreadsheet 
var ss = SpreadsheetApp.openById('KEY_TAKEN_OUT');//Change the spreadhseet key to yours 
var sheet = ss.getSheets()[0]; 
sheet.getRange(sheet.getLastRow()+1, 1, 1, 5).setValues([[new Date(), eventDate,eventPeople,eventCompany,eventName,eventTime,eventPhone,eventEmail,eventTaken, 'Event created']]); 

//Show the confirmation message 
app.add(app.createLabel('Event created Successfully')); 
//make the form panel invisible 
app.getElementById('panel').setVisible(false); 
return app; 
} 

    //If an error occurs, show it on the panel 
    catch(e){ 
    app.add(app.createLabel('Error occured: '+e)); 
    return app; 
} 
} 

回答

1

此行可能沒有返回值:

var cal = CalendarApp.getCalendarsByName('Phoenix Reservations')[0];//Change the calendar name 

你可以登錄它來確認這樣Logger.log(cal)

是「鳳凰預訂」日曆名稱,你自己或者你有寫訪問至 ?

編輯:你可以測試這個簡單的功能,看看這個日曆是否一切正常嗎? 它會剛剛創建一個活動。

function testcal(){ 
    var cal = CalendarApp.openByName('Phoenix Reservations');// or you can replace this with your var definition : same result normally ;-) 
    if (cal) { 
    var title = 'Test Event'; 
    var start = new Date(); 
    var end = new Date(start.valueOf()+60*60*1000); 
    Logger.log(cal.getName()+' '+start+' '+end) 
    var desc = 'Created using Google Script'; 
    var loc = 'there'; 

    var event = cal.createEvent(title, start, end, { 
     description : desc, 
     location : loc 
    }); 
    } 
} 

編輯2:我修改了記錄器,使其顯示日曆名稱。

+0

鳳凰預訂是日程表,我有寫權限。 – user1492352

+0

你是否按照建議檢查了記錄器? –

+0

我試圖模仿這種設置:https://sites.google.com/site/appsscripttutorial/calendar-services/create-calendar-events-by-submitting-form 記錄器沒有返回值,它通過就好了。 – user1492352

相關問題