Google apps script 日历API,仅使用Google Apps脚本修改以下事件
从2021年2月8日开始,每周一我都会重复这些事件。我想修改即将到来的2021年2月28日,以便所有未来的活动将在每周三重新安排。请注意,事件必须更新,并且将包含以下所有事件(保留eventID)Google apps script 日历API,仅使用Google Apps脚本修改以下事件,google-apps-script,google-calendar-api,Google Apps Script,Google Calendar Api,从2021年2月8日开始,每周一我都会重复这些事件。我想修改即将到来的2021年2月28日,以便所有未来的活动将在每周三重新安排。请注意,事件必须更新,并且将包含以下所有事件(保留eventID) 此代码将更新所有重复事件,包括过去的事件。但我只需要更新以下事件。根据的官方文档,不可能保留eventId,因为您需要根据首选修改创建新事件,更新旧的重复事件并更改其参数,直到结束系列 为了在给定(目标)实例上或之后更改重复事件的所有实例,必须发出两个单独的API请求。这些请求将原始定期事件分为两部分
此代码将更新所有重复事件,包括过去的事件。但我只需要更新以下事件。根据的官方文档,不可能保留eventId,因为您需要根据首选修改创建新事件,更新旧的重复事件并更改其
参数,直到
结束系列
为了在给定(目标)实例上或之后更改重复事件的所有实例,必须发出两个单独的API请求。这些请求将原始定期事件分为两部分:保留未更改实例的原始事件和具有应用更改实例的新定期事件:
直到组件设置为第一个目标实例开始时间之前的点。或者,您可以设置计数
组件,而不是直到
(更新) 示例代码:
function updateRecurr() {
var calendarId = 'c_9cdqeqqluk7vsessartfxxxxx';
var eventId = '17a97q639vmtkoghcxxxxx';
//Update eventseries, change "until" parameter in rrule to Feb. 27, 2020
var event = {
recurrence:[
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20210227;BYDAY=MO"
]
}
updatedEvent = Calendar.Events.patch(event,calendarId,eventId);
Logger.log(updatedEvent);
//Create new event having the same important info with different start time and rrule
var newEvent = {
summary: updatedEvent.summary,
description: updatedEvent.description,
start:{
date: Utilities.formatDate(new Date("March 3, 2021"), Session.getScriptTimeZone(), "yyyy-MM-dd")
},
end:{
date: Utilities.formatDate(new Date("March 3, 2021"), Session.getScriptTimeZone(), "yyyy-MM-dd")
},
recurrence:[
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20210331;BYDAY=WE"
]
}
var newEventSeries = Calendar.Events.insert(newEvent,calendarId);
Logger.log(newEventSeries);
}
输出:
之前:
function updateRecurr() {
var calendarId = 'c_9cdqeqqluk7vsessartfxxxxx';
var eventId = '17a97q639vmtkoghcxxxxx';
//Update eventseries, change "until" parameter in rrule to Feb. 27, 2020
var event = {
recurrence:[
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20210227;BYDAY=MO"
]
}
updatedEvent = Calendar.Events.patch(event,calendarId,eventId);
Logger.log(updatedEvent);
//Create new event having the same important info with different start time and rrule
var newEvent = {
summary: updatedEvent.summary,
description: updatedEvent.description,
start:{
date: Utilities.formatDate(new Date("March 3, 2021"), Session.getScriptTimeZone(), "yyyy-MM-dd")
},
end:{
date: Utilities.formatDate(new Date("March 3, 2021"), Session.getScriptTimeZone(), "yyyy-MM-dd")
},
recurrence:[
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20210331;BYDAY=WE"
]
}
var newEventSeries = Calendar.Events.insert(newEvent,calendarId);
Logger.log(newEventSeries);
}
之后:
function updateRecurr() {
var calendarId = 'c_9cdqeqqluk7vsessartfxxxxx';
var eventId = '17a97q639vmtkoghcxxxxx';
//Update eventseries, change "until" parameter in rrule to Feb. 27, 2020
var event = {
recurrence:[
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20210227;BYDAY=MO"
]
}
updatedEvent = Calendar.Events.patch(event,calendarId,eventId);
Logger.log(updatedEvent);
//Create new event having the same important info with different start time and rrule
var newEvent = {
summary: updatedEvent.summary,
description: updatedEvent.description,
start:{
date: Utilities.formatDate(new Date("March 3, 2021"), Session.getScriptTimeZone(), "yyyy-MM-dd")
},
end:{
date: Utilities.formatDate(new Date("March 3, 2021"), Session.getScriptTimeZone(), "yyyy-MM-dd")
},
recurrence:[
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20210331;BYDAY=WE"
]
}
var newEventSeries = Calendar.Events.insert(newEvent,calendarId);
Logger.log(newEventSeries);
}
注: 在新创建的事件系列中,您会注意到我将开始日期设置为“2021年3月3日”,这是因为如果我将其设置为“2021年2月28日”,那么也将在该特定日期创建事件。但在现实生活中,我使用谷歌日历创建了一个事件,并将开始日期设置为“2021年2月28日”,事件系列每周发生一次,每周三。事件中设定的实际开始日期为“2021年3月3日”
只需复制上一系列活动中的所有其他重要活动详细信息(如果有)。在提供的示例中,我刚刚配置了事件标题和描述。谢谢Ron,是否可以使用您建议的代码片段执行以下操作?请参考更新的答案