function updateHolidayCalendars() {
var employees = SpreadsheetApp.openById('GoogleSheetID').getSheets()[0].getDataRange().getValues();
employees.forEach(function(employee) {
var userEmail = employee[0]; // Column with email addresses
var region = employee[1]; // Column with region information
var calendarId = getCalendarIdByRegion(region); // Function to get the right calendar ID based on region
var holidays = CalendarApp.getCalendarById(calendarId).getEventsForDay(new Date());
holidays.forEach(function(holiday) {
var event = CalendarApp.getCalendarById(calendarId).createEvent(
holiday.getTitle() + ' - ' + employee[2], // Assuming employee name is in third column
holiday.getStartTime(),
holiday.getEndTime(),
{description: 'Holiday observed by: ' + userEmail}
);
});
});
}
function getCalendarIdByRegion(region) {
var calendarIds = {
'US': 'testcalendarID',
};
return calendarIds[region];
}
Error
TypeError: Cannot read properties of null (reading 'getEventsForDay')