You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Apps Script高级日历服务添加Google日历事件提醒失效问题

问题描述
  • 团队从Microsoft Exchange迁移至Gmail后,需要自动化休假申请流程,实现申请状态和团队共享日历的同步
  • 现有基于Advanced Calendar Services开发的Google Apps Script已实现大部分逻辑:
    • 新提交的休假申请:创建黄色日历事件,透明度为「空闲」、无提醒,符合预期
    • 审批通过的申请:将事件更新为绿色、透明度改为「忙碌」,并添加提醒
  • 现存问题:提醒配置始终不生效,其余功能运行正常,原代码如下:
if ((requestStatus == "Approved") || (eventStatus == "confirmed")) {
  var eventReminders = "{method: email, minutes: 900}";
  } else {
  var eventReminders = null;  //No reminders
}
  //var eventReminders = setEventReminders(requestStatus); //set calendar reminders

  // Compose event details based on the data read from the relevant row in the sheet
  var newEvent = {
    summary: 'Time-Off (' + requestStatus + ') ' + requestorName,
    description: eventDescription,
    colorId: colorE,
    transparency: eventTransparency,
    reminders: { 
      useDefault: false, 
      overrides: [ 
        eventReminders 
        ]
    },
    start: {
      date : startDate //use date instead of dateTime to create full day event so the event will pin on the top of the calendar
    },
    end: {
      date : endDate
    },
    attendees: [
      {email: requestorEmail}
    ]
  };
  //Create the event in the calendar  
  updateCalendar (eventAction, newEvent, rowE, eventRequestID);
}
故障原因

核心问题是eventReminders的格式错误:你将提醒配置写成了JSON字符串,但Google Calendar API要求reminders.overrides字段接收的是JavaScript对象数组,传入字符串会被API直接忽略,导致提醒无法生效。
另外未审批状态下如果直接把null放进overrides数组,可能触发API参数校验错误,需要额外处理。

修正方案
  1. 去掉eventReminders外层的引号,直接定义为原生JS对象
  2. 无提醒场景下将overrides设为空数组,不要传入null
  3. 注意900分钟对应15小时提醒,可根据实际需求调整minutes数值

修正后的代码片段:

if ((requestStatus == "Approved") || (eventStatus == "confirmed")) {
  // 直接使用对象格式,不要用引号包裹
  var eventReminders = {method: "email", minutes: 900};
} else {
  var eventReminders = null;
}

var newEvent = {
  summary: 'Time-Off (' + requestStatus + ') ' + requestorName,
  description: eventDescription,
  colorId: colorE,
  transparency: eventTransparency,
  reminders: { 
    useDefault: false, 
    // 有提醒时放入数组,无提醒时传空数组
    overrides: eventReminders ? [eventReminders] : []
  },
  start: {
    date : startDate
  },
  end: {
    date : endDate
  },
  attendees: [
    {email: requestorEmail}
  ]
};

updateCalendar (eventAction, newEvent, rowE, eventRequestID);

内容的提问来源于stack exchange,提问作者VCTRT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 19:36:18