Class TriggerBuilder | Apps Script | Google for Developers (original) (raw)
Class TriggerBuilder
Stay organized with collections Save and categorize content based on your preferences.
TriggerBuilder
A generic builder for script triggers.
Detailed documentation
forDocument(document)
Creates and returns a [DocumentTriggerBuilder](/apps-script/reference/script/document-trigger-builder)
tied to the given document.
ScriptApp.newTrigger('myFunction') .forDocument(DocumentApp.getActiveDocument()) .onOpen() .create();
Parameters
Name | Type | Description |
---|---|---|
document | Document | the document |
Return
[DocumentTriggerBuilder](/apps-script/reference/script/document-trigger-builder)
— the new DocumentTriggerBuilder
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
forDocument(key)
Creates and returns a [DocumentTriggerBuilder](/apps-script/reference/script/document-trigger-builder)
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
[DocumentTriggerBuilder](/apps-script/reference/script/document-trigger-builder)
— the new DocumentTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
forForm(form)
Creates and returns a [FormTriggerBuilder](/apps-script/reference/script/form-trigger-builder)
tied to the given form.
ScriptApp.newTrigger('myFunction') .forForm(FormApp.getActiveForm()) .onFormSubmit() .create();
Parameters
Name | Type | Description |
---|---|---|
form | Form | the form |
Return
[FormTriggerBuilder](/apps-script/reference/script/form-trigger-builder)
— the new FormTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/forms.currentonly
https://www.googleapis.com/auth/forms
forForm(key)
Creates and returns a [FormTriggerBuilder](/apps-script/reference/script/form-trigger-builder)
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
[FormTriggerBuilder](/apps-script/reference/script/form-trigger-builder)
— the new FormTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/forms.currentonly
https://www.googleapis.com/auth/forms
forSpreadsheet(sheet)
Creates and returns a [SpreadsheetTriggerBuilder](/apps-script/reference/script/spreadsheet-trigger-builder)
tied to the given spreadsheet.
ScriptApp.newTrigger('myFunction') .forSpreadsheet(SpreadsheetApp.getActive()) .onEdit() .create();
Parameters
Name | Type | Description |
---|---|---|
sheet | Spreadsheet | the spreadsheet |
Return
[SpreadsheetTriggerBuilder](/apps-script/reference/script/spreadsheet-trigger-builder)
— the new SpreadsheetTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
forSpreadsheet(key)
Creates and returns a [SpreadsheetTriggerBuilder](/apps-script/reference/script/spreadsheet-trigger-builder)
tied to the spreadsheet with the given ID.
ScriptApp.newTrigger('myFunction') .forSpreadsheet('1234567890abcdefghijklmnopqrstuvwxyz') .onEdit() .create();
Parameters
Name | Type | Description |
---|---|---|
key | String | the ID for the spreadsheet |
Return
[SpreadsheetTriggerBuilder](/apps-script/reference/script/spreadsheet-trigger-builder)
— the new SpreadsheetTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
forUserCalendar(emailId)
Returns a builder for building calendar triggers.
Parameters
Name | Type | Description |
---|---|---|
emailId | String | email ID of the user calendar the trigger monitors. |
Return
[CalendarTriggerBuilder](/apps-script/reference/script/calendar-trigger-builder)
— The new CalendarTriggerBuilder.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/calendar.readonly
https://www.googleapis.com/auth/calendar.events
https://www.googleapis.com/auth/calendar.events.readonly
https://www.google.com/calendar/feeds
timeBased()
Creates and returns a [ClockTriggerBuilder](/apps-script/reference/script/clock-trigger-builder)
for building time-based triggers.
ScriptApp.newTrigger('myFunction').timeBased().atDate(2013, 10, 31).create();
Return
[ClockTriggerBuilder](/apps-script/reference/script/clock-trigger-builder)
— the new ClockTriggerBuilder
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/script.scriptapp
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.