2013-02-17 116 views
2

谷歌腳本文檔狀態CalendarEventSeries應該至少有兩個方法setRecurrence()。當我嘗試使用它:CalendarEventSeries,缺少setRecurrence()方法?

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

我得到這個錯誤:

Cannot find method (class)setRecurrence(object,$Proxy754). (line 60, file "Sync").

的方法是在CalendarEventSeries調用是肯定的。如何解決該錯誤?

回答

1

您顯示的示例適用於all day Events(第一次出現時只指定一個日期),您是應用於此類事件還是應用於「正常」事件?

在這最後一種情況下,您應該爲第一次出現提供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 
     } 
    } 
    } 
} 

編輯您的評論如下:它的工作原理完全SAM E對於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) 
     } 
    } 
    } 
} 

enter image description here

+0

感謝您的迴應,我的情況涉及到「生日」datefield,我試圖搬入日曆。所以我說的是整天事件在過去的指定日期開始,沒有任何結束日期,我使用CreateAllDayEventSeries()來創建它,它需要一個名稱,開始日期和重新設置。 我想隨後移動這個事件系列(意味着所有屬於它)到另一天...沒有任何指定的結束日期 它現在有意義嗎? – 2013-02-17 22:23:52

+0

感謝您的評論,我編輯了我的迴應與一個新的例子對應於您的使用案例 – 2013-02-18 07:08:27

+0

現在我很困惑。你的例子工作,然後我必須檢查m中的錯誤y代碼:| – 2013-02-18 13:59:56

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) 

非常感謝嗶嘰的幫助,這是crutial!不幸的是沒有聲望15我不能給你任何點:(

+0

PS。 Serge,你知道嗎?我們怎樣才能從CalendarEventSeries對象獲取開始日期?我擔心這是不可能的,所以我以一種不同的方式做了事情。但也許你知道一些沒有記錄的後門? :) – 2013-02-18 14:46:04

+0

這似乎確實是不可能的,也許你可以發佈有關該主題的新問題和/或針對[問題跟蹤器]提出改進請求(http://code.google.com/p/google-如果沒有有趣的答案出現的話,應用程序腳本問題/問題/列表)。 – 2013-02-18 17:24:43

+0

這正是我在一個小時前做過的:)再次感謝您的幫助。 – 2013-02-18 18:03:19