我正在尝试创建一个Google脚本,该脚本会在一个时间范围内遍历每个事件,并将这些事件修改为每年一次的重复事件。目前,我错误地将一堆生日放在日历中,但未将其设置为重复性。我不想创建一个脚本来将它们设置为每年重复运行,而不是手动进行操作。我被困在第12行上。
注意:目前,我只是让我的代码搜索一个称为“ john bday”的特定事件,但是一旦我得到它来正确修改现有事件,它将删除“ if”语句。请告知并谢谢您。
function myFunction() {
var fromDate = new Date(2019,0,1,0,0,0); //This is January 1, 2019
var toDate = new Date(2019,2,31,0,0,0); //This is March 31, 2019
var calname = "testing calendar";
var findtitle = "john bday";
var calendar = CalendarApp.getCalendarsByName(calname)[0];
var events = calendar.getEvents(fromDate,toDate);
for (var i=0; i<events.length;i++) {
var ev = events[i];
if (ev.getTitle()==findtitle) {
CalendarApp.newRecurrence().addYearlyRule();
}
}
}
答案 0 :(得分:0)
我可以通过将事件复制到新系列中,然后删除原始事件来使其工作。感谢所有看过这个的人。
function myFunction() {
var fromDate = new Date(2018,6,1,0,0,0); //This is July 1, 2018
var toDate = new Date(2019,0,31,0,0,0); //This is January 31, 2019
var calname = "testing calendar";
var calendar = CalendarApp.getCalendarsByName(calname)[0];
var events = calendar.getEvents(fromDate,toDate);
var newRecurrence = CalendarApp.newRecurrence().addYearlyRule();
for (var i in events){
var ev = events[i];
var newEvent = calendar.createEventSeries(events[i].getTitle(), events[i].getStartTime(), events[i].getEndTime(), newRecurrence)
ev.deleteEvent();
}
}