Class TriggerBuilder Stay organized with collections Save and categorize content based on your preferences.
Page Summary
TriggerBuilder is a generic builder used for creating script triggers in Apps Script.
It provides methods to create trigger builders for specific Google services such as Documents, Forms, Spreadsheets, and Calendar.
TriggerBuilder also allows the creation of time-based triggers using the
timeBased()method.Each method returns a specialized builder for the respective service or time-based triggers.
Creating triggers requires appropriate authorization scopes depending on the service being used.
A generic builder for script triggers.
Methods
| Method | Return type | Brief description |
|---|---|---|
for | Document | Creates and returns aDocument tied to the given document. |
for | Document | Creates and returns aDocument tied to the document with the given ID. |
for | Form | Creates and returns aForm tied to the given form. |
for | Form | Creates and returns aForm tied to the form with the given ID. |
for | Spreadsheet | Creates and returns aSpreadsheet tied to the given spreadsheet. |
for | Spreadsheet | Creates and returns aSpreadsheet tied to the spreadsheet with the givenID. |
for | Calendar | Returns a builder for building calendar triggers. |
time | Clock | Creates and returns aClock for building time-based triggers. |
Detailed documentation
forDocument(document)
Creates and returns aDocument tied to the given document.
ScriptApp .newTrigger('myFunction').forDocument(DocumentApp.getActiveDocument()).onOpen().create();
Parameters
| Name | Type | Description |
|---|---|---|
document | Document | the document |
Return
Document — the new DocumentTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
forDocument(key)
Creates and returns aDocument tied to the document with the given ID.
ScriptApp .newTrigger('myFunction').forDocument('1234567890abcdefghijklmnopqrstuvwxyz').onOpen().create();
Parameters
| Name | Type | Description |
|---|---|---|
key | String | the ID for the document |
Return
Document — the new DocumentTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
forForm(form)
Creates and returns aForm tied to the given form.
ScriptApp .newTrigger('myFunction').forForm(FormApp.getActiveForm()).onFormSubmit().create();
Parameters
| Name | Type | Description |
|---|---|---|
form | Form | the form |
Return
Form — the new FormTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
forForm(key)
Creates and returns aForm tied to the form with the given ID.
ScriptApp .newTrigger('myFunction').forForm('1234567890abcdefghijklmnopqrstuvwxyz').onFormSubmit().create();
Parameters
| Name | Type | Description |
|---|---|---|
key | String | the ID for the form |
Return
Form — the new FormTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/forms.currentonlyhttps://www.googleapis.com/auth/forms
forSpreadsheet(sheet)
Creates and returns aSpreadsheet tied to the given spreadsheet.
ScriptApp .newTrigger('myFunction').forSpreadsheet(SpreadsheetApp.getActive()).onEdit().create();
Parameters
| Name | Type | Description |
|---|---|---|
sheet | Spreadsheet | the spreadsheet |
Return
Spreadsheet — the new SpreadsheetTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
forSpreadsheet(key)
Creates and returns aSpreadsheet tied to the spreadsheet with the givenID.
ScriptApp .newTrigger('myFunction').forSpreadsheet('1234567890abcdefghijklmnopqrstuvwxyz').onEdit().create();
Parameters
| Name | Type | Description |
|---|---|---|
key | String | the ID for the spreadsheet |
Return
Spreadsheet — the new SpreadsheetTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/spreadsheets.currentonlyhttps://www.googleapis.com/auth/spreadsheets
forUserCalendar(emailId)
Returns a builder for building calendar triggers.
Parameters
| Name | Type | Description |
|---|---|---|
email | String | email ID of the user calendar the trigger monitors. |
Return
Calendar — The new CalendarTriggerBuilder.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/calendarhttps://www.googleapis.com/auth/calendar.readonlyhttps://www.googleapis.com/auth/calendar.eventshttps://www.googleapis.com/auth/calendar.events.readonlyhttps://www.google.com/calendar/feeds
timeBased()
Creates and returns aClock for building time-based triggers.
ScriptApp .newTrigger('myFunction').timeBased().atDate(2013,10,31).create();
Return
Clock — the new ClockTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/script.scriptapp
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.