Stay organized with collections Save and categorize content based on your preferences.
TriggerA script trigger.
Detailed documentationgetEventType()
Returns the event type that the trigger fires on.
const triggers = ScriptApp.getProjectTriggers(); for (let 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
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
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.
const triggers = ScriptApp.getProjectTriggers(); for (let 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
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.
ReturnString
— the id of the entity in the publisher that this is a trigger for
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.
ReturnString
— the unique identifier of the trigger
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-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-03 UTC."],[[["A script trigger is a function that automatically runs in response to a certain event, like opening a document, editing a cell, or a timed event."],["`Trigger` object provides methods to access information about the trigger such as its event type, associated function, source, source ID, and a unique identifier."],["`getEventType()`, `getHandlerFunction()`, `getTriggerSource()`, `getTriggerSourceId()`, and `getUniqueId()` methods provide information on the trigger's configuration and behavior."],["All methods associated with the Trigger object necessitate authorization with the scope `https://www.googleapis.com/auth/script.scriptapp`."]]],["This document details the functionality of script triggers, which are automated actions. Key actions include retrieving information about a trigger using five methods: `getEventType()`, which identifies the event type that activates the trigger; `getHandlerFunction()`, which returns the function executed when the trigger fires; `getTriggerSource()`, which specifies the event source; `getTriggerSourceId()`, which provides the source's ID; and `getUniqueId()`, which offers a unique identifier for the trigger. All methods require specific authorization scopes.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4