@bolish said in Getting Google Contacts birthdays into Calendar:
function Sync_Birth_Cal() {
// Calendars adress (ID)
var calendarSource = CalendarApp.getCalendarById(“THE ID OF YOUR CONTACT CALENDAR”);
var calendarDestination = CalendarApp.getCalendarById(“THE ID OF THE CREATED CALENDAR”);
// Start and End Date definition
var Today = new Date();
var StartDeleteDate = new Date();
var EndDeleteDate = new Date();
var StartCopyDate = new Date();
var EndCopyDate = new Date();
StartDeleteDate.setDate(Today.getDate()-400);
EndDeleteDate.setDate(Today.getDate()+400);
StartCopyDate.setDate(Today.getDate()-360);
EndCopyDate.setDate(Today.getDate()+360);
// first deletes all datas in calendar
var eventToDelete = calendarDestination.getEvents(StartDeleteDate, EndDeleteDate);
for (var i = 0; i < eventToDelete.length; i++) {
eventToDelete[i].deleteEvent();
}
// then copy everything again
var eventToCopy = calendarSource.getEvents(StartCopyDate, EndCopyDate);
for (var t in eventToCopy){
var newEvent = calendarDestination.createEvent(eventToCopy[t].getTitle(), eventToCopy[t].getStartTime(), eventToCopy[t].getEndTime());
}
}
I get this error when I try to run the script:
TypeError: Cannot call method “getEvents” of null. (line 25, file “Code”)
I got that sorted, forgot the 2 IDs.
Now I get:
Service invoked too many times in a short time: calendar. Try Utilities.sleep(1000) between calls. (line 37, file “Code”)
MW