Boost Productivity with Google Apps Script Triggers: Types and How to Set Them Up
With Google Apps Script, you can streamline your workflow, but doesn’t it feel cumbersome to run the script manually every time?
By using Google Apps Script triggers, you can integrate with Google services like Sheets and Forms to automate script execution seamlessly.
This eliminates the need for manual operations, enabling greater efficiency and significant time savings in your workflow.
In this article, we will introduce the types of Google Apps Script triggers and explain how to set them up.
Main Types of Triggers
- Triggers Based on Spreadsheet Actions
- Time-Driven Triggers
- Triggers Based on Calendar Events
Triggers are mechanisms that automatically execute scripts based on specific conditions or events.
This allows you to save effort and efficiently manage your tasks.
Here, we’ll introduce the main types of triggers.
Triggers Based on Spreadsheet Actions
Scripts can be executed based on actions in Google Sheets, such as cell edits or sheet modifications, serving as triggers to automate tasks.
You can choose from the following options:
On Open | Executes the script when the spreadsheet is opened. |
On Edit | Executes the script when a cell in the spreadsheet is edited. |
On Change | Executes the script when the structure of the sheet is modified (e.g., adding or deleting a sheet). |
On Form Submit | Executes the script when data submitted through a Google Form is added to the spreadsheet. |
Time-Driven Triggers
Time-driven triggers execute scripts at specific time intervals or according to a predefined schedule. These triggers are ideal for automating recurring tasks.
Here are the available options:
Specific date and time | Execute the script only once at a specific date and time. |
Minute Timer | Runs the script every 1, 5, 10, 15, or 30 minutes. |
Hourly Timer | Executes the script every hour or at specific hourly intervals. |
Daily Timer | Schedules the script to run once a day, with options to specify the time of execution. |
Weekly Timer | Runs the script on specific days of the week at a predefined time. |
Monthly Timer | Executes the script on a specific day of the month at a specified time. |
Triggering by Calendar Events
Triggers Based on Calendar Events
Calender updated | Runs the script whenever an existing event is modified. By using this trigger, you can automate processes based on changes made to your calendar. |
Writing Triggers in Scripts
To set up triggers programmatically, you can use the ScriptApp service in Google Apps Script. This allows you to create, manage, and customize triggers directly within your script.
For example, you can schedule a script to fetch Google Analytics data precisely at 7:00 AM every morning, or execute it under specific conditions, providing finer control compared to standard time-based triggers.
This enables the automation of daily data collection, streamlining data management and improving efficiency.
How to Set Up Triggers
(Excluding the method of writing triggers directly in the script)
In Google Sheets, click on Extensions
> Apps Script
.
In the Apps Script editor, click the clock icon 🕒 on the left sidebar, or go to Triggers
> Current project's triggers
.
Click + Add Trigger
.
(Example of selecting a time-driven trigger)
- Select the Function to Execute
-
- Specify the function to run when the trigger is activated.
- The
fetchGoogleNewsByCountryAndSection
function was created in the article linked below.
- Select Execution Deployment:
-
- Choose which version of the script to use when the trigger is executed.
- Typically, select
Head
to use the latest version.
- Select Event Source
-
- Specify the event that will trigger the execution.
- Options include choices such as “Time-Driven.”
- A time-driven trigger executes the script based on a predefined schedule.
- Select the Type of Time-Based Trigger
-
- This option allows you to set how frequently the script should run.
- If you select “Date-Based Timer,” you can schedule execution within hourly intervals.
(Partial explanation for “Date-Based Timer”)
Click Save
to activate the trigger.
With this setup, the selected script will execute whenever the specified event occurs.
The triggers you set up will be displayed in a list.
Advantages and Disadvantages of Trigger Settings
Advantages | Disadvantages |
---|---|
Automation of Tasks Reduction in Human Errors Timely Notifications | Possibility of Execution at Unexpected Times Difficulty in Troubleshooting Errors Limitations on Execution Frequency |
- Automation of Tasks
-
By automating daily routine tasks, you can significantly reduce working hours.
For example, regular data retrieval, updates, and transfers can be automated seamlessly.
- Reduction in Human Errors
-
By using triggers, scripts are executed automatically at the right time, preventing missed executions or running the wrong script.
- Timely Notifications
-
By automating script execution in response to real-time actions such as spreadsheet updates or form submissions, you can efficiently handle tasks as they occur.
There are also some disadvantages to setting up triggers.
- Possibility of Execution at Unexpected Times
-
Triggers automatically execute scripts when the specified conditions are met, but they may sometimes run at unexpected times.
This can lead to risks such as unnecessary data updates or changes.
- Difficulty in Troubleshooting Errors
-
Unlike manually running scripts, it becomes more challenging to check error details in real time.
- Limitations on Execution Frequency
-
Trigger execution is subject to Google’s limitations, with a restricted number of executions allowed per day.
If this limit is exceeded, the script will stop, potentially leaving essential processes incomplete.
Limitations of Trigger Execution
Item | Personal (e.g., gmail.com) or G Suite Free Edition | Google Workspace Account |
---|---|---|
Total Trigger Execution Time | 90 minutes/day | 6 hours/day |
Number of Triggers | Up to 20 triggers per script | Up to 20 triggers per script |
- Total Trigger Execution Time:
-
Each account has a limit on the total trigger execution time allowed per day.
For personal accounts, the limit is 90 minutes per day, while Google Workspace accounts allow up to 6 hours per day.
When running long scripts with triggers, it’s important to ensure that the total execution time does not exceed the daily limit.
- Number of Triggers:
-
The number of triggers that can be set for each script is limited to a maximum of 20 per script for both personal accounts and Google Workspace accounts.
When setting multiple triggers, it’s important to use only the necessary ones and manage them to stay within the limit.
For more details, please refer to the Google Workspace website.
Examples of Trigger Usage
By utilizing triggers, you can automate tasks by executing specific scripts on a regular schedule.
For instance:
- Fetching news updates and storing them in a Google Sheet.
- Retrieving data from Google Analytics for daily or weekly reporting.
Conclusion
In this article, we introduced the types of triggers and how to set them up.
By keeping the limitations in mind, setting up triggers can help you automate tasks and reduce manual effort, making your workflow more efficient.
Our company offers support for improving work efficiency through the use of Google Apps Script.
If you need assistance with Google Apps Script customization or error resolution, please feel free to contact us.
We are fully committed to supporting your business improvements.
Contact us here
Comments