Coding level: Beginner
Duration: 15 min
Project type: Automation with a time-driven trigger
Objectives
- Understand what the solution does.
- Understand what the Apps Script services do within the solution.
- Set up the script.
- Run the script.
About this solution
A shared vacation calendar is a great tool for helping your team collaborate; anyone can determine who's out of the office at a glance. This solution lets you see when your colleagues are out of the office, with no manual entry required.
How it works
This solution populates a shared vacation calendar based on the individual calendars of each person in a Google Group. When someone books time off, they add an event to their personal Google Calendar using a keyword like "Vacation" or "Out of office."
Every hour, the script scans the calendars of the members in the group and syncs appropriate events to the shared calendar. You can change how often the script scans for new events.
This solution only accesses Calendar events that your colleagues have made visible to you via their privacy settings.
Apps Script services
This solution uses the following services:
- Groups service–Determines the members of the Google Group.
- Calendar advanced service–Provides access to the Google Calendar API and searches for events on the group members' calendars.
Prerequisites
To use this sample, you need the following prerequisites:
- A Google Account (Google Workspace accounts might require administrator approval).
- A web browser with access to the internet.
Set up the script
Create a team vacation calendar
- Open Google Calendar.
- Create a new calendar called "Team Vacations."
- In the calendar's settings, under Integrate calendar, copy the Calendar ID.
Create the Apps Script project
- Click the following button to open the Vacation Calendar
Apps Script project.
Open the project - Click Overview .
- On the overview page, click Make a copy .
- In your copied Apps Script project, set the
variable
TEAM_CALENDAR_ID
to the ID of the calendar you created earlier. - Set the variable
GROUP_EMAIL
to the email address of a Google Group containing your team members. - Next to Services, click Add a service .
- Select Google Calendar API and click Add.
Run the script
- In your copied Apps Script project, in the function dropdown, select setup.
- Click Run.
When prompted, authorize the script. If the OAuth consent screen displays the warning, This app isn't verified, continue by selecting Advanced > Go to {Project Name} (unsafe).
When complete, return to Calendar to confirm the Team Vacations calendar is populated with events.
Review the code
To review the Apps Script code for this solution, click View source code below:
View source code
Code.gs
Modifications
You can edit the team vacation calendar automation as much as you'd like to fit your needs. Below is an optional change to modify the trigger.
Change how often the script scans for new events
To change how often the script runs, take the following steps:
- In the Apps Script project, click Triggers .
- Next to the trigger, click Edit Trigger .
- Select your changes and click Save.
Contributors
This sample is maintained by Google with the help of Google Developer Experts.