Class Trigger
Stay organized with collections
Save and categorize content based on your preferences.
Trigger
A script trigger.
Detailed documentation
getEventType()
Returns the event type that the trigger fires on.
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
if (triggers[i].getEventType() == ScriptApp.EventType.CLOCK) {
// Some code here - other options are:
// ScriptApp.EventType.ON_EDIT
// ScriptApp.EventType.ON_FORM_SUBMIT
// ScriptApp.EventType.ON_OPEN
}
}
Return
EventType
— the event type that this is a trigger for
Authorization
Scripts that use this method require authorization with one or more of the following
scopes
:
-
https://www.googleapis.com/auth/script.scriptapp
getHandlerFunction()
Returns the function that will be called when the trigger fires.
// Create a trigger for the script.
ScriptApp.newTrigger('myFunction').forSpreadsheet('id of my spreadsheet').onEdit().create();
Logger.log(ScriptApp.getProjectTriggers()[0].getHandlerFunction()); // logs "myFunction"
Return
String
— the method name
Authorization
Scripts that use this method require authorization with one or more of the following
scopes
:
-
https://www.googleapis.com/auth/script.scriptapp
getTriggerSource()
Returns the source of events that will cause the trigger to fire.
For example, a spreadsheet onEdit trigger would return SPREADSHEETS, or a time based trigger
would return CLOCK.
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
if (triggers[i].getTriggerSource() == ScriptApp.TriggerSource.CLOCK) {
Logger.log(triggers[i].getUniqueId() + " source is clock");
} else if (triggers[i].getTriggerSource() == ScriptApp.TriggerSource.SPREADSHEETS) {
Logger.log(triggers[i].getUniqueId() + " source is spreadsheets");
}
}
Return
TriggerSource
— the publisher this is a trigger for
Authorization
Scripts that use this method require authorization with one or more of the following
scopes
:
-
https://www.googleapis.com/auth/script.scriptapp
getTriggerSourceId()
Returns the id specific to the source.
For example, if the trigger source is a spreadsheet, this would be the id of the
spreadsheet. For clock events this returns null.
Return
String
— the id of the entity in the publisher that this is a trigger for
Authorization
Scripts that use this method require authorization with one or more of the following
scopes
:
-
https://www.googleapis.com/auth/script.scriptapp
getUniqueId()
Returns a unique identifier that can be used to distinguish triggers from each other.
Return
String
— the unique identifier of the trigger
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 2018-08-20 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]