Troubleshooting of google apps script

From LemonWiki共筆
Jump to navigation Jump to search

Troubleshooting of google apps script about CalendarApp

Fix: TypeError: Cannot read property 'createEvent' of null[edit]

Code

let cal = CalendarApp.getCalendarById(calendar_id);
let event = cal.createEvent(title, start_time, end_time);


Error message

TypeError: Cannot read property 'createEvent' of null
setUpCalendar	@ 程式碼.gs:42

Solution: Verify the cal variable is not null.

Code

let cal = CalendarApp.getCalendarById(calendar_id);
Logger.log('The calendar is named "%s".', cal.getName());

Fix: Exception: Action not allowed[edit]

Error message

Exception: Action not allowed
setUpCalendar	@ 程式碼.gs:45

Code

let cal = CalendarApp.getCalendarById(calendar_id);
let event = cal.createEvent(title, start_time, end_time, options);

Solution: Verify the gmail account running apps script was allowed to write the google calendar

Fix: TypeError: cal.createEvent(...).createEventFromDescription is not a function[edit]

Error message

TypeError: cal.createEvent(...).createEventFromDescription is not a function
setUpCalendar	@ 程式碼.gs:45

Root cause: use the wrong function

Code

let options = {description: description, guests: email_of_guest};
let event = cal.createEvent(title, start_time, end_time, options);

Further reading[edit]