有没有办法找到是否删除了重复系列中的一个或多个事件?
Is there a way to find if one or more events within a recurring series has been deleted?
我正在使用以下代码检查 Google 日历中是否有已取消的事件。它适用于定期的、非重复发生的事件。但是,当用户删除重复事件系列中的单个事件时,我 运行 遇到了问题。
function checkForCancelledEvents(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Data Source");
ss.setActiveSheet(sheet);
//sort by date added
var lastRow = sheet.getLastRow();
var range = sheet.getRange(1,2,lastRow, 5)
var values = range.getValues();
//in the array the 3 position is the eventId, the 4 position is the calendar ID, I'm putting more into the array since I was playing around with also using the start date or time to solve the problem
//loop through all using Calendar.Events.get
for (i=1;i<values.length;i++) {
var splitEventID = values[i][3].toString().split("@")[0] //remove the calendarID from the eventID
if (Calendar.Events.get(values[i][4],splitEventID).status === "cancelled") {
//the below clears the content of the row that contains the cancelled events
//the range has to start at i + 1 since the values include the header row, but the for loop starts at 1 instead of 0 to prevent the API from calling with data from header row (which produces an error). So i + 1 gives the accurate row number for which the cancelled event lives
var clearRange = sheet.getRange(i + 1,1,1,7)
clearRange.clearContent()
} else {
//Logger.log("this is NOT cancelled")
}
}
}
问题是重复发生的事件都包含相同的 eventID 和 calendarID。它们也具有相同的 iCalUID。重复事件确实具有不同的 id
,但非重复事件没有相同的 id
格式。我尝试使用 Calendar.event.list 并在循环系列中添加每个事件的 timeMin
,但是该事件仍然列为 confirmed
,即使它已被删除。
有没有办法找到重复系列中的单个事件是否已被删除?
我相信你的目标如下。
- 来自
Is there a way to find if a single event within a recurring series has been deleted?
,您想知道是否使用 Google Apps 脚本删除了重复事件中的一个事件。
在这种情况下,我想当使用“Events: instances”这个方法时,或许可以达到你的目的。示例脚本如下
示例脚本:
在您使用此脚本之前,please enable Calendar API at Advanced Google services。
var calendarId = "###"; // Please set the calendar ID.
var eventId = "###"; // Please set the event ID.
var ar = [];
var pageToken = "";
do {
var res = Calendar.Events.instances(calendarId, eventId, {maxResults: 2500, showDeleted: true, pageToken});
if (res.items.length > 0) ar = [...ar, ...res.items.filter(({status}) => status == "cancelled")];
pageToken = res.nextPageToken;
} while (pageToken);
if (ar.length > 0) {
// When "ar" has the values, the events are deleted from the recurring events.
// do something.
}
- 在上面的脚本中,您可以在
ar
处看到被删除事件的信息。
注:
- 这是一个简单的示例脚本。所以请根据您的实际情况进行修改。
参考:
我正在使用以下代码检查 Google 日历中是否有已取消的事件。它适用于定期的、非重复发生的事件。但是,当用户删除重复事件系列中的单个事件时,我 运行 遇到了问题。
function checkForCancelledEvents(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Data Source");
ss.setActiveSheet(sheet);
//sort by date added
var lastRow = sheet.getLastRow();
var range = sheet.getRange(1,2,lastRow, 5)
var values = range.getValues();
//in the array the 3 position is the eventId, the 4 position is the calendar ID, I'm putting more into the array since I was playing around with also using the start date or time to solve the problem
//loop through all using Calendar.Events.get
for (i=1;i<values.length;i++) {
var splitEventID = values[i][3].toString().split("@")[0] //remove the calendarID from the eventID
if (Calendar.Events.get(values[i][4],splitEventID).status === "cancelled") {
//the below clears the content of the row that contains the cancelled events
//the range has to start at i + 1 since the values include the header row, but the for loop starts at 1 instead of 0 to prevent the API from calling with data from header row (which produces an error). So i + 1 gives the accurate row number for which the cancelled event lives
var clearRange = sheet.getRange(i + 1,1,1,7)
clearRange.clearContent()
} else {
//Logger.log("this is NOT cancelled")
}
}
}
问题是重复发生的事件都包含相同的 eventID 和 calendarID。它们也具有相同的 iCalUID。重复事件确实具有不同的 id
,但非重复事件没有相同的 id
格式。我尝试使用 Calendar.event.list 并在循环系列中添加每个事件的 timeMin
,但是该事件仍然列为 confirmed
,即使它已被删除。
有没有办法找到重复系列中的单个事件是否已被删除?
我相信你的目标如下。
- 来自
Is there a way to find if a single event within a recurring series has been deleted?
,您想知道是否使用 Google Apps 脚本删除了重复事件中的一个事件。
在这种情况下,我想当使用“Events: instances”这个方法时,或许可以达到你的目的。示例脚本如下
示例脚本:
在您使用此脚本之前,please enable Calendar API at Advanced Google services。
var calendarId = "###"; // Please set the calendar ID.
var eventId = "###"; // Please set the event ID.
var ar = [];
var pageToken = "";
do {
var res = Calendar.Events.instances(calendarId, eventId, {maxResults: 2500, showDeleted: true, pageToken});
if (res.items.length > 0) ar = [...ar, ...res.items.filter(({status}) => status == "cancelled")];
pageToken = res.nextPageToken;
} while (pageToken);
if (ar.length > 0) {
// When "ar" has the values, the events are deleted from the recurring events.
// do something.
}
- 在上面的脚本中,您可以在
ar
处看到被删除事件的信息。
注:
- 这是一个简单的示例脚本。所以请根据您的实际情况进行修改。