使用Google脚本移动日历事件 [英] Move calendar events with Google scripts
本文介绍了使用Google脚本移动日历事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个Google脚本,该脚本将从一个日历(pubCal)在给定时间范围内的所有事件转移到另一个日历(privCal).
I'm trying to write a Google script that will move from one calendar (pubCal) all events within a given time frame to another calendar (privCal).
我不确定为什么,但是代码在以下行处中断:"Calendar.Events.move(pubCalId,eventToMove.getId(),privCalId);",并显示错误消息:未找到(第18行,文件代码")"
I'm not sure why, but the code breaks at the line: "Calendar.Events.move(pubCalId, eventToMove.getId(), privCalId);", with the error message: "Not Found (line 18, file "Code")"
此错误消息是什么意思?
What does this error message mean?
function export_gcal_to_gsheet(){
//pubCall: public calendar
//privCal private calendar
var pubCalId = "addressForPubicCal@group.calendar.google.com";
var privCalId = "addressForPrivateCal@group.calendar.google.com";
var pubCal = CalendarApp.getCalendarById(pubCalId);
//Change date range to move events from pubCal to privCal
var startDate = "January 1, 2018 00:00:00 CST";
var endDate = "January 04, 2018 23:59:59 CST";
// Extract events between certain dates in public calendar.
var events = pubCal.getEvents(new Date(startDate), new Date(endDate));
//Loop through all Calendar events
while (events.length > 0){
var eventToMove = events.shift();
Calendar.Events.move(pubCalId, eventToMove.getId(), privCalId);
}
}
推荐答案
以下修改如何?
Calendar.Events.move(pubCalId, eventToMove.getId(), privCalId);
收件人:
Calendar.Events.move(pubCalId, eventToMove.getId().replace("@google.com", ""), privCalId);
注意:
- 检索到的
eventToMove.getId()的ID是
##### @ google.com
.但是用于Calendar.Events.move()
的ID是#####
.因此需要从###### @ google.com
中删除@ google.com
.- 在您的脚本中,因为找不到
##### @ google.com
,所以会发生错误. - The id retrieved
eventToMove.getId()
is#####@google.com
. But the id which is used forCalendar.Events.move()
is#####
. So@google.com
is required to be removed from#####@google.com
.- In your script, because
#####@google.com
cannot be found, the error occurs.
如果我误解了你的问题,对不起.
If I misunderstand your question, I'm sorry.
这篇关于使用Google脚本移动日历事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- In your script, because
Note :
- 在您的脚本中,因为找不到
查看全文