【问题标题】:Create a Calendar event on the specific date at the specific time and then end on that date at another time在特定日期的特定时间创建日历事件,然后在该日期的另一个时间结束
【发布时间】:2023-03-23 17:10:01
【问题描述】:

我有一个非常规矩的问题! 我正在为一个学区创建一个工作流程。 本质上 .. 老师填写了一个 Google 表单 我使用 Autocrat 自动创建一个 Google Doc,其中包含为校长精心布置的信息。
我在顶部为每个管理员编写了批准或不批准请求的脚本按钮,批准后它会自动将请求转发给下一个管理员并在底部签名等。

所以我正在研究如何制作实地考察申请表,我正试图让它将活动添加到日历中,事实证明这非常困难。 我在表单上创建了一个表格,以便更轻松地从文档中获取数据,日期格式为 2021 年 7 月 2 日在其自己的单元格中,因为这就是 Google 表单将其放入的方式。时间在另一个单元格中,并且格式为:8:00:00 AM。

此表在 Google Doc 上,是一个 2x4 表,看起来像这样:

Field Trip Date: | 7/2/2021 

Destination Address: | Full Address Here 
 
Departure Time: | 8:00:00 AM 

Time of Departure from the Field Trip Location: | 9:00:00 AM  

出发时间为活动开始时间。 从该地点出发的时间是结束时间。

我正在使用以下脚本将数据作为变量拉入

var TableCal = location.getTables()[3];
var startDate = tableCal.getCell(0, 1);
var address = tableCal.getCell(1, 1);
var startTime = tableCal.getCell(2, 1);
var endTime = tableCal.getCell(3, 1);

我在整个脚本的其他领域都使用了上述方法。

我的脚本就是问题
没有错误,但它没有显示在日历上。 我拥有日历的完全权限。

var event = CalendarApp.getCalendarById('lotsolettersandnumbers@group.calendar.google.com').createEvent(trip, 
  new Date(startTime),
  new Date(endTime),
  {location: address}); 

注意 startTime 和 endTime 都是上午 8:00:00 和上午 9:00:00 的时间。在上面我没有使用 startDate ,它是事件的日期。

我确实尝试过创建一个新变量 -

var comma = ', '; 
var start = startDate + comma + startTime; 
var end = startDate + comma + endTime;

然后我用 startTime 代替 start,用 endTime 代替 end。 这也没有用。
脚本说明它完成时没有错误,但日历上没有显示任何内容。

有什么想法吗???

我需要的是在特定日期的特定时间创建一个日历事件,然后在该日期的另一个时间结束。

【问题讨论】:

  • 对于事件创建功能,您的使用时间将被忽略。因此,只要 startTime endTime 是 Date() 或构造函数识别的字符串,这应该可以工作。 var event = CalendarApp.getCalendarById('lotsolettersandnumbers@group.calendar.google.com').createEvent(trip, new Date(startTime), new Date(endTime), {location: address}); 但是由于您没有提供该信息,因此我无能为力。
  • 也许这会更有意义......
  • 我没有看到任何变化
  • 只是让他们感到抱歉
  • 这就是它在文档startDate Date the date when the event starts (only the day is used; the time is ignored) 中所说的,所以如果你只是使用可能不起作用的时间,或者它可能会在 1970 年 1 月 1 日创建事件,则不确定。最好按照文档的说明进行操作。

标签: javascript google-apps-script google-calendar-api


【解决方案1】:

我的和你的很相似,但它可以工作。我只是通过使用空格(没有逗号)来附加它们,尽管你的应该也可以。

代码:

function myFunction() {
  var startDate = "7/2/2021";
  var address = "Full Address Here";
  var startTime = "8:00:00 AM";
  var endTime = "9:00:00 AM";

  var start = startDate + " " + startTime;
  var end = startDate + " " + endTime;

  Logger.log(new Date(start));
  Logger.log(new Date(end));

  CalendarApp.getDefaultCalendar().createEvent('sample event',
    new Date(start),
    new Date(end),
    {location: address});
}

输出:

日志:

您是否能够记录您的startend?尝试将它们转换为日期并检查它们的值。在您的帖子中包含这些值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 2020-04-28
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多