[NOTE: updated to better reflect understanding of the issue]
I am trying to move all events from one Google calendar to another using Google Scripts.
I have written the following code:
function move_all_events()
{
var fromYear = 2016;
var toYear=2020
var fromDate = new Date(fromYear,0,1,0,0,0); //Year, Month (where 0 = Jan, 1 = Feb...), Hour, Min, Sec, Millisecond
var toDate = new Date(toYear,1,0,0,0);
var fromCalendarName = 'Calendar1';
var toCalendarName = 'Calendar2';
// Move from start of fromYear to start of toYear (for month 0 = Jan, 1 = Feb...)
var fromCalendar = CalendarApp.getCalendarsByName(fromCalendarName)[0];
var toCalendar = CalendarApp.getCalendarsByName(toCalendarName)[0];
var fromCalendarId = fromCalendar.getId();
var toCalendarId = toCalendar.getId();
Logger.log(fromCalendarId);
Logger.log(toCalendarId);
var events = fromCalendar.getEvents(fromDate, toDate);
for(var i=0; i<events.length;i++){
var evId = events[i].getId().replace("@google.com", "");
Logger.log(evId); // show event Id in log
Calendar.Events.move(fromCalendarId, evId, toCalendarId);
}
}
The above code WORKS fine when the events to-be-moved have been created manually from within Google Calendar.
However, the code FAILS when the events to-be-moved were created externally in an ical/ics file and then IMPORTED into Google calendar.
When I run the code, I get the following error:
API call to calendar.events.move failed with error: Not Found (line 86, file "Code")
where line 86 is the line with Calendar.Events.move.
Note the log shows:
[20-04-24 01:26:15:031 EDT] myname@gmail.com
[20-04-24 01:26:15:032 EDT] asfdsfdsfdsfekwlkkllkpauc700@group.calendar.google.com
[20-04-24 01:26:15:986 EDT] myeventidprefix-a3a597f53ff059959e950fc513df33af
All seems "correct" and indeed the event Id is exactly the UID that I created externally in the ics file that I then imported.
Yet somehow, it seems that Calendar.Events.move is not able to find the event itself in the fromCalendar.
Any idea what is going wrong here?
A SECOND problem that I noted is that even when the routine works (i.e. for events created within Google Calendar), the 'notifications' are not moved. I.e., if I create an event in fromCalendar with notifications, the moved events in toCalendar have lost the notification. Note that neither calendar has Event or 'All Day' notifications turned-on generally.
Interestingly, if I move that same event back to fromCalendar, the notifications magically reappear.
So any idea why the notifications are seemingly still internally intact but are not visible along with the other event data