起初我认为以下错误是日期/时间问题,但经过进一步检查,似乎与设置title
的{{1}}有关:
CalendarEvent
脚本的和第374行如下:
[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]
变量很好 - eventToUpdate.setTitle(title);
(记录时)是eventToUpdate
对象,因此CalendarEvent
应该可以正常工作。 setTitle(title)
变量包含一个字符串,如执行脚本中的错误所示。
这最近开始发生,没有对代码进行任何更改。我创建了一些函数来测试标题更改,结果发现只有在事件的时间也发生变化时才会出现错误,而如果时间是则仅在标题更改之前更改。如果在标题更改后更改时间,则没有错误。请参阅以下代码:
title
所以问题是:为什么在更改标题之前更改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();
}
的日期/时间会导致此错误?
然后,这是一个错误吗?
答案 0 :(得分:2)
序列号必须是非递减的,某些更改会增加序列号,请参阅 http://tools.ietf.org/html/rfc5545#section-3.8.7.4
您应该始终使用当前序列号修改最新版本的事件。在这种情况下,我假设在每个setter之后,更改会立即传播到服务器。这意味着你可以尝试在第一次修改之后重新获取“eventToChange”,然后再进行下一次修改。