Google Apps Script: Time Triggers, ClockTriggerBuilder, ScriptApp
One of the most powerful things about Google Apps Script is the ability to automatically complete tasks with time-driven triggers. You can set up your code to run any one of your functions in your script by the minute, hour, day, week, or month. You can even set it to run based on a specific date.
Have a look at the time-driven trigger options below:
-
- Specific Date and Time: Based on: YYYY-MM-DD HH: MM format
- Minute: Every minute or every 5, 10, 15 or 30 minutes.
- Hour: Every hour or every 2, 4, 6, 8 or 12 hours.
- Day: At a time within an hourly bracket. For example:
- Midnight to 1 am,
- 3 pm to 4 pm
- Month: On a specific day of a calendar month at a specific time. For example:
-
- Every 3 day of the month at between 3 am and 4 am.
-
There are two approaches to setting up these time-based triggers. The first one is by simply using the Trigger creator inside the G Suite Developer Hub. This allows you to select the function that you want to add a trigger to for your project and fill out a simple form to determine when you want your trigger to run.
Alternatively, you can create a time trigger programmatically using the ClockTriggerBuilder class.
In this tutorial, we will build on a previous project we’ve called The Badger, that contains a task check off Google Sheet. If the user does not check off their sheet by the due date, then we can send them an HTML email reminder.
Don’t worry, I will provide the starter code and the Google Sheet for you in a minute. However, if you want to learn how I created the email reminder for The Badger you can follow the tutorial here:
Google Apps Script: Create an HTML email reminder service from Google Sheet data.
If you want to see how I created the Spreadsheet, you can check out this link:
Google Sheets: How to create a task completion check sheet.