At first I thought the following error was a date/time problem, but upon further inspection it seems to be related to setting the title
of a CalendarEvent
:
[14-05-08 16:47:26:183 EDT] CalendarEvent.setTitle([HOLD: TES 101-01, Test, 10 -- Test Training (1 of 1)]) [0.067 seconds]
[14-05-08 16:47:26:189 EDT] Execution failed: Service error: CalendarApp: Cannot decrease the sequence number of an event (line 374, file "Save Changes") [1.245 seconds total runtime]
and line 374 of the script is the following:
eventToUpdate.setTitle(title);
The variables are fine - eventToUpdate
(when logged) is a CalendarEvent
object, so setTitle(title)
should work fine. The title
variable contains a string, as shown in the error from the Execution Transcript.
This started happening recently, without any changes to the code. I created a few functions to test title-changes, and it turns out that the error only occurs when the time of the event is also changed, and only if the time is changed before the title is changed. If the time is changed after the title is changed, there is no error. See the following code:
function eventTitleChangeTest() {
var calStart = new Date("Thu May 08 17:00:00 GMT-04:00 2014");
var calEnd = new Date("Thu May 08 18:00:00 GMT-04:00 2014");
var calendar = CalendarApp.getOwnedCalendarsByName(getLibraryProperty('LRCalName'))[0];
var event = calendar.createEvent("Temporary Title", calStart, calEnd);
var eventID = event.getId();
Logger.log(event.getTitle());
changeTitleById(eventID);
changeTitleByTime(calStart, calEnd);
}
function changeTitleById(id) {
var calendar = CalendarApp.getOwnedCalendarsByName(getLibraryProperty('LRCalName'))[0];
var event = calendar.getEventSeriesById(id);
event.setTitle("ID-based Title Change");
Logger.log(event.getTitle());
}
function changeTitleByTime(start, end) {
var calendar = CalendarApp.getOwnedCalendarsByName(getLibraryProperty('LRCalName'))[0];
var events = calendar.getEvents(start, end);
var eventToChange = events[0];
// The line below is the problem (it comes before the title change)
eventToChange.setTime(new Date("Wed May 07 17:00:00 GMT-04:00 2014"), new Date("Wed May 07 17:00:00 GMT-04:00 2014"));
eventToChange.setTitle("Time-based Title Change");
// But if I change the time AFTER the title, it works without a problem. But why?
//eventToChange.setTime(new Date("Wed May 07 17:00:00 GMT-04:00 2014"), new Date("Wed May 07 17:00:00 GMT-04:00 2014"));
Logger.log(eventToChange.getTitle());
}
function deleteEvent(id) {
var calendar = CalendarApp.getOwnedCalendarsByName(getLibraryProperty('LRCalName'))[0];
calendar.getEventSeriesById(id).deleteEventSeries();
}
So the question is: Why does changing the date/time of a CalendarEvent
before changing the title cause this error?
And subsequently, is this a bug?