简体   繁体   English

Apps 脚本和 Google 表格,创建日历事件

[英]Apps Script and Google Sheets, Creating calendar event

When I try to run the following code when the start and end dates are the same (to create a calendar event from data submitted through Google Forms), I get this error: Exception: Event start date must be before event end date.当我尝试在开始日期和结束日期相同时运行以下代码(从通过 Google 表单提交的数据创建日历事件),我收到此错误:异常:事件开始日期必须在事件结束日期之前。

else if (approval == Approval.Approved) {
// If approved, create a calendar event.
CalendarApp.getCalendarById(email)
    .createAllDayEvent(
        'OOO - Out Of Office',
        startDate,
        endDate,
        {
          description: message,
          guests: additionalEmail,
          sendInvites: true,
        });

Since employees can request a full or partial day off, I would like the script to be able to run even if the values are the same.由于员工可以请求全部或部分休假,我希望脚本能够运行,即使值相同。 How would I make this happen?我将如何做到这一点?

Also, for background, I have very limited coding experience (next to nothing except for basic R), so if it's possible, please dumb it down for me.另外,对于背景,我的编码经验非常有限(除了基本的 R 之外几乎没有),所以如果可能的话,请为我简化它。 Thank you so much for your time and help!非常感谢您的时间和帮助!

As per documentation ( https://developers.google.com/apps-script/reference/calendar/calendar ), you can:根据文档( https://developers.google.com/apps-script/reference/calendar/calendar ),您可以:

Create a one-day event like so: createAllDayEvent(title, date)像这样创建一个一日活动: createAllDayEvent(title, date)

.createAllDayEvent(
        'OOO - Out Of Office',
        startDate,
        {
          description: message,
          guests: additionalEmail,
          sendInvites: true,
        });

Create multiple-day events like so: createAllDayEvent(title, startDate, endDate)像这样创建多天事件: createAllDayEvent(title, startDate, endDate)

.createAllDayEvent(
        'OOO - Out Of Office',
        startDate,
        endDate,
        {
          description: message,
          guests: additionalEmail,
          sendInvites: true,
        });

Create partial-day events like so: createEvent(title, startTime, endTime, options)像这样创建部分日事件: createEvent(title, startTime, endTime, options)

.createEvent(
        'OOO - Out Of Office',
        startTime,
        endTime,
        {
          description: message,
          guests: additionalEmail,
          sendInvites: true,
        });

With regard to times in Apps Script, here's a snippet of syntax:关于 Apps Script 中的时间,这里有一段语法:

new Date('July 20, 1969 20:00:00 UTC');

And docs link: https://developers.google.com/google-ads/scripts/docs/features/dates和文档链接: https ://developers.google.com/google-ads/scripts/docs/features/dates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Google 表格脚本创建 Google 日历事件有错误 - Creating a Google Calendar Event with Google Sheets script has Errors Google Apps脚本-createEvent函数未创建日历事件 - Google Apps Script - createEvent function not creating calendar event Google Apps 脚本两次创建日历条目 - Google Apps Script is creating calendar entry twice 使用html5时间和日期输入的Google Apps脚本创建日历事件? - Creating a calendar event with Google Apps Script from html5 time and date inputs? 从导入日期来自电子表格创建Google日历事件时出现setHours()错误 - Apps脚本 - setHours() Error when Creating a Google Calendar Event from Imported Date Coming From Spreadsheet - Apps Script Google 日历事件不会使用 Apps 脚本 deleteEvent() 方法删除 - Google Calendar event will not delete with Apps Script deleteEvent() method 在 Google Apps Script 日历活动中创建动态参与者列表 - Create dynamic list of attendees in Google Apps Script calendar event 如何使用Apps脚本获取Google日历事件附件 - How to get Google calendar event attachment using Apps Script Google Apps 脚本 - 从电子表格创建日历事件 - Google Apps Script - Create Calendar Event from Spreadsheet 在 Google 应用脚本中需要帮助以在 Google 日历中创建事件 - Need help in Google App Script for Creating event in Google Calendar
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM