2014-11-01 167 views
0

我想创建一个脚本,所以当我在一个谷歌日历中创建一个事件它会自动复制另一个谷歌日历中的事件。我曾尝试使用下面的代码尝试(换日历的ID与我自己的 - 假设我使用完整的ID例如[email protected]等):谷歌脚本重复新的谷歌日历事件到另一个日历

function myFunction() { 
var calendarSource = CalendarApp.getCalendarById("calendarID"); 
var calendarDestination = CalendarApp.getCalendarById("calendarID"); 
var eventToCopy = calendarSource.getEvents(new Date("July 21, 2009 EST"), new Date("July 22, 2009 EST")); 

//read up: https://developers.google.com/apps-script/class_recurrence 
var newRecurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10); 

for (var i in eventToCopy){ 
if (eventToCopy[i].getTitle() == "event name"){ 
    var newEvent = calendarDestination.createEventSeries(eventToCopy[i].getTitle(), eventToCopy[i].getStartTime(), eventToCopy[i].getEndTime(), newRecurrence); 
} 

} 

似乎没有任何虽然发生。任何人都给我一个头马?我只想要这个触发创建一个新事件。

+0

可能重复[我怎样才能复制(复制)的日历事件将使用谷歌脚本再历?](http://stackoverflow.com/questions/12497158/how-can-i-copy-duplicate -a-日历事件 - 进入 - 使用另一个历-谷歌-S) – Mogsdad 2014-11-05 01:40:54

回答

0

在您发布的代码片段中,如果由于if (eventToCopy[i].getTitle() == "event name"){行的标题等于“事件名称”,则只会将事件复制到新日历中。您在源日历中的事件可能没有此标题,因此没有任何内容正在复制。您应该能够删除此if条件以获取要复制的所有事件。

function myFunction() { 
    var calendarSource = CalendarApp.getCalendarById("calendarID"); 
    var calendarDestination = CalendarApp.getCalendarById("calendarID"); 
    var eventToCopy = calendarSource.getEvents(new Date("July 21, 2009 EST"), new Date("July 22, 2009 EST")); 

    //read up: https://developers.google.com/apps-script/class_recurrence 
    var newRecurrence = CalendarApp.newRecurrence().addWeeklyRule().times(10); 

    for (var i in eventToCopy){ 
    var newEvent = calendarDestination.createEventSeries(eventToCopy[i].getTitle(), eventToCopy[i].getStartTime(), eventToCopy[i].getEndTime(), newRecurrence); 
    } 
}