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.
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. Thank you so much for your time and help!
As per documentation (https://developers.google.com/apps-script/reference/calendar/calendar), you can:
Create a one-day event like so: 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(
'OOO - Out Of Office',
startDate,
endDate,
{
description: message,
guests: additionalEmail,
sendInvites: true,
});
Create partial-day events like so: 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:
new Date('July 20, 1969 20:00:00 UTC');
And docs link: https://developers.google.com/google-ads/scripts/docs/features/dates