2

谷歌脚本文档状态 CalendarEventSeries 应该至少有两个方法setRecurrence()。当我尝试使用它时:

setRecurrence(new Date(), CalendarApp.newRecurrence().addYearlyRule().interval(1));

我收到此错误:

找不到方法(类)setRecurrence(对象,$Proxy754)。(第 60 行,文件“同步”)。

该方法肯定会被调用CalendarEventSeries。如何解决该错误?

4

2 回答 2

1

您展示的示例适用于全天事件(仅指定第一次发生的日期),您是应用于此类事件还是“正常”事件?

在最后一种情况下,您应该为第一次出现提供 2 个日期(开始和结束)。

上面的链接显示了非常清楚的文档......

这是一个“端到端”示例,展示了它是如何工作的,第一个函数创建一个从今天开始每年重复的事件,第二个函数将这个重复更改为每天,从今天开始......

它使用您的默认日历

function createTestSerie(){
  var cal = CalendarApp.getDefaultCalendar()
  if (cal) {
  var title = 'Test Event';
  var desc = 'Created using Google Apps Script';
  var loc = 'Here, there and everywhere...';
  var recur = CalendarApp.newRecurrence().addYearlyRule().interval(1)
  var start = new Date();
  var end = new Date(start.valueOf()+3600*1000);

  var event = cal.createEventSeries(title, start, end,recur,{description:desc,location:loc});// event will be every year and last 1 hour
  }   
}

function modifyRecurrence(){
  var cal = CalendarApp.getDefaultCalendar()
  if (cal) {
  var start = new Date();
  var end = new Date(start.getTime()+3600*1000*2);
  var events = cal.getEvents(new Date("February 16, 2013 08:00:00 PDT"), new Date("February 19, 2013 08:00:00 PDT"))
    for(i in events){
     if(events[i].getTitle()=='Test Event'){
       var recur = CalendarApp.newRecurrence().addDailyRule().interval(1)
       var eventId = events[i].getId()
       cal.getEventSeriesById(eventId).setRecurrence(recur, start, end);// now events will be lasting 2 hours evey day starting today
       }
   }
   }
}

根据您的评论进行编辑: 它对 allDayEvents 的工作方式完全相同,这是一个修改后的示例代码:

function createAllDaySerie(){
  var cal = CalendarApp.getDefaultCalendar()
  if (cal) {
  var title = 'All Day Test Event';
  var start = new Date();
  var desc = 'Created using Google Apps Script';
  var loc = 'home';
  var recur = CalendarApp.newRecurrence().addYearlyRule().interval(4)
  var start = new Date();
  var event = cal.createAllDayEventSeries(title, start,recur,{description:desc,location:loc});// event will be every 4 years starting today
  }   
}

function modifyAllDayRecurrence(){
  var cal = CalendarApp.getDefaultCalendar()
  if (cal) {
  var start = new Date("February 19, 2010 08:00:00 PDT");// here you can choose any date you like that will be the new start date.
  var events = cal.getEvents(new Date("February 16, 2013 08:00:00 PDT"), new Date("February 22, 2013 08:00:00 PDT"))
    for(i in events){
     if(events[i].getTitle()=='All Day Test Event'){
       var recur = CalendarApp.newRecurrence().addYearlyRule().interval(1)
       var eventId = events[i].getId()
       cal.getEventSeriesById(eventId).setRecurrence(recur, start);// now events will occur once a year starting on february 19, 2010 (see screen capture below)
       }
   }
   }
}

在此处输入图像描述

于 2013-02-17T14:01:45.087 回答
1

我们有我的问题的解决方案。API 文档中有一个错误。那里写着:

method setRecurrence(startDate, recurrence)
Changes the recurrence rules of this series to a new rule, and to an all day event.

但实际上方法 setRecurrence() 将这些参数颠倒过来:

method setRecurrence(recurrence, startDate)

非常感谢 Serge 的帮助,这很重要!不幸的是,没有声誉 15 我无法给你任何积分:(

于 2013-02-18T14:31:59.220 回答