2014-05-08 26 views
1

起初我还以为下面的错误是一个日期/时间的问题,但经过进一步检查它似乎与设定的title一个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] 

和脚本的行374是以下几点:

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(); 
} 

所以,问题是:改变标题原因这个错误之前为什么改变CalendarEvent的日期/时间?

然后,这是一个错误?

回答

2

序列号必须在非递减和一些变化增加了序列号,请参阅 http://tools.ietf.org/html/rfc5545#section-3.8.7.4

您应该始终修改最近一次事件的版本与当前的序列号。在这种情况下,我假设在每个设置者之后立即将更改传播到服务器。这意味着您可以尝试在第一次修改后重新获取“eventToChange”,然后再执行下一个修改。

+1

Luc,关于序列号的有趣想法 - 我在RFC中查找并找不到增加或减少序列号的更改。但是,我能够找到[定义]的资源(http://www.kanzaki.com/docs/ical/sequence.html)导致序列号增加的原因。所以,如果错误是序列号不能*减少*,那么我可能会试图改变一个旧的* iCal对象的序列号,一个旧的参考?我会尽快看看代码,并让你知道它是如何发生的。非常好的建议! –

+0

谢谢,克里斯!请让我知道它是如何去;) – luc

+0

吕克,这的确是答案!不再收到错误,谢谢你的提示:) –