Additional addition
Google Apps Script has a standard CalendarApp
class, which is a library for operating Google Calendar.
Here, we will explain how to add a schedule to the calendar using the CalendarApp
class.
Since GAS will access Google Calendar, you will need to set the authority at the first run.
Prerequisite
When adding a schedule to the calendar, you must first get the additional calendar.
Click here for how to get the calendar.
Add an event
Function to use
Use the following functions to add the event.
CalendarApp.Calendar.createEvent([event name], [Starting day], [End date and time], [option]);
Sample code
const CALENDAR_ID = '___Target calendar ID___';
function myFunction() {
const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
if (!calendar) {
console.log('I couldn't find the calendar');
return;
}
const from = new Date();
const to = new Date();
from.setHours(from.getHours() + 1);
to.setHours(to.getHours() + 2);
calendar.createEvent('Events added from Google Apps Script', from, to);
}
By execution, an event based on the executable time is registered.
option
The fourth argument options can be omitted.
The items that can be specified are as follows.
calendar.createEvent(title, from, to, {
description: 'Event details',
location: 'Event location',
guests: '[email protected],[email protected]', // Specify the e -mail address to be invited as a guest as a comma separation
sendInvites: false, // In the case of True, send an invitation email
});
Add a date unit event
How to add a date unit event without specifying time.
Function to use
Use the following functions to add the event.
CalendarApp.Calendar.createAllDayEvent([event name], [date]);
Sample code
const CALENDAR_ID = '___Target calendar ID___';
function myFunction() {
const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
if (!calendar) {
console.log('I couldn't find the calendar');
return;
}
const date = new Date();
calendar.createAllDayEvent('Date level event added from Google Apps Script', date);
}
By execution, an event based on the executable time is registered.