At first, I am a very new programmer, so I apologize for my ignorance. I wrote this code using google apps script to take data from a google sheet, and import that to a calendar.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Class");
var data = sheet.getDataRange().getValues();
var today = Utilities.formatDate(new Date(), "GMT+9", "yyyy-MM-dd");
function caldel() {
var eventCal = CalendarApp.getCalendarById('//gmail address');
for (var i=73; data.length; i++) {
var evtcall = eventCal.getEventById(data[i][52]);
evtcall.deleteEvent();
}
}
It used to run well, but today, error message poped up.
"TypeError: Cannot read property 'getEventById' of null
caldel @ Code.gs:8"
I don't know why this error came out. If there is anyone who knows or fixes this error, plz help me. Thank you.
Assumming that you are using a real calendar id (like Gmail address) in
var eventCal = CalendarApp.getCalendarById('//gmail address');
you are getting null assigned to eventCal because the effective user don't have access to the referred calendar.
As a rule of thumb avoid sign-in into multiple accounts when running a Google Apps Script function. This because calling a server-side function from a dialog, sidebar or web-app might be done using the default account instead of the account that has access to the required resources.