Renvoie un identifiant unique qui permet de distinguer les déclencheurs les uns des autres.
Documentation détaillée
getEventType()
Indique le type d'événement sur lequel le déclencheur se déclenche.
consttriggers=ScriptApp.getProjectTriggers();for(leti=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}}
Renvois
EventType : type d'événement pour lequel il s'agit d'un déclencheur
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des champs d'application suivants:
https://www.googleapis.com/auth/script.scriptapp
getHandlerFunction()
Renvoie la fonction qui sera appelée lorsque le déclencheur se déclenchera.
// Create a trigger for the script.ScriptApp.newTrigger('myFunction').forSpreadsheet('id of my spreadsheet').onEdit().create();Logger.log(ScriptApp.getProjectTriggers()[0].getHandlerFunction());// logs "myFunction"
Renvois
String : nom de la méthode
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des champs d'application suivants:
https://www.googleapis.com/auth/script.scriptapp
getTriggerSource()
Indique la source des événements qui déclencheront le déclencheur.
Par exemple, un déclencheur de feuille de calcul onEdit renverrait SPREADSHEETS, ou un déclencheur basé sur le temps renverrait CLOCK.
consttriggers=ScriptApp.getProjectTriggers();for(leti=0;i < triggers.length;i++){if(triggers[i].getTriggerSource()===ScriptApp.TriggerSource.CLOCK){Logger.log(`${triggers[i].getUniqueId()} source is clock`);}elseif(triggers[i].getTriggerSource()===ScriptApp.TriggerSource.SPREADSHEETS){Logger.log(`${triggers[i].getUniqueId()} source is spreadsheets`);}}
Renvois
TriggerSource : éditeur pour lequel le déclencheur est défini
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des champs d'application suivants:
https://www.googleapis.com/auth/script.scriptapp
getTriggerSourceId()
Renvoie l'ID propre à la source.
Par exemple, si la source du déclencheur est une feuille de calcul, il s'agit de l'ID de la feuille de calcul. Pour les événements d'horloge, cette valeur renvoie la valeur nulle.
Renvois
String : ID de l'entité de l'éditeur pour laquelle il s'agit d'un déclencheur
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des champs d'application suivants:
https://www.googleapis.com/auth/script.scriptapp
getUniqueId()
Renvoie un identifiant unique qui permet de distinguer les déclencheurs les uns des autres.
Renvois
String : identifiant unique du déclencheur
Autorisation
Les scripts qui utilisent cette méthode nécessitent une autorisation avec un ou plusieurs des champs d'application suivants:
https://www.googleapis.com/auth/script.scriptapp
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/07/26 (UTC)."],[[["\u003cp\u003eA 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.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eTrigger\u003c/code\u003e object provides methods to access information about the trigger such as its event type, associated function, source, source ID, and a unique identifier.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetEventType()\u003c/code\u003e, \u003ccode\u003egetHandlerFunction()\u003c/code\u003e, \u003ccode\u003egetTriggerSource()\u003c/code\u003e, \u003ccode\u003egetTriggerSourceId()\u003c/code\u003e, and \u003ccode\u003egetUniqueId()\u003c/code\u003e methods provide information on the trigger's configuration and behavior.\u003c/p\u003e\n"],["\u003cp\u003eAll methods associated with the Trigger object necessitate authorization with the scope \u003ccode\u003ehttps://www.googleapis.com/auth/script.scriptapp\u003c/code\u003e.\u003c/p\u003e\n"]]],["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"],null,["Trigger\n\nA script trigger. \n\nMethods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------|---------------------------------------------------------------|---------------------------------------------------------------------------------------|\n| [getEventType()](#getEventType()) | [EventType](/apps-script/reference/script/event-type) | Returns the event type that the trigger fires on. |\n| [getHandlerFunction()](#getHandlerFunction()) | `String` | Returns the function that will be called when the trigger fires. |\n| [getTriggerSource()](#getTriggerSource()) | [TriggerSource](/apps-script/reference/script/trigger-source) | Returns the source of events that will cause the trigger to fire. |\n| [getTriggerSourceId()](#getTriggerSourceId()) | `String` | Returns the id specific to the source. |\n| [getUniqueId()](#getUniqueId()) | `String` | Returns a unique identifier that can be used to distinguish triggers from each other. |\n\nDetailed documentation \n\n`get``Event``Type()` \nReturns the event type that the trigger fires on.\n\n```javascript\nconst triggers = ScriptApp.getProjectTriggers();\nfor (let i = 0; i \u003c triggers.length; i++) {\n if (triggers[i].getEventType() === ScriptApp.EventType.CLOCK) {\n // Some code here - other options are:\n // ScriptApp.EventType.ON_EDIT\n // ScriptApp.EventType.ON_FORM_SUBMIT\n // ScriptApp.EventType.ON_OPEN\n }\n}\n```\n\nReturn\n\n\n[EventType](/apps-script/reference/script/event-type) --- the event type that this is a trigger for\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/script.scriptapp`\n\n*** ** * ** ***\n\n`get``Handler``Function()` \nReturns the function that will be called when the trigger fires.\n\n```javascript\n// Create a trigger for the script.\nScriptApp.newTrigger('myFunction')\n .forSpreadsheet('id of my spreadsheet')\n .onEdit()\n .create();\nLogger.log(ScriptApp.getProjectTriggers()[0]\n .getHandlerFunction()); // logs \"myFunction\"\n```\n\nReturn\n\n\n`String` --- the method name\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/script.scriptapp`\n\n*** ** * ** ***\n\n`get``Trigger``Source()` \nReturns the source of events that will cause the trigger to fire.\n\nFor example, a spreadsheet onEdit trigger would return SPREADSHEETS, or a time based trigger\nwould return CLOCK.\n\n```javascript\nconst triggers = ScriptApp.getProjectTriggers();\nfor (let i = 0; i \u003c triggers.length; i++) {\n if (triggers[i].getTriggerSource() === ScriptApp.TriggerSource.CLOCK) {\n Logger.log(`${triggers[i].getUniqueId()} source is clock`);\n } else if (\n triggers[i].getTriggerSource() === ScriptApp.TriggerSource.SPREADSHEETS) {\n Logger.log(`${triggers[i].getUniqueId()} source is spreadsheets`);\n }\n}\n```\n\nReturn\n\n\n[TriggerSource](/apps-script/reference/script/trigger-source) --- the publisher this is a trigger for\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/script.scriptapp`\n\n*** ** * ** ***\n\n`get``Trigger``Source``Id()` \nReturns the id specific to the source.\n\nFor example, if the trigger source is a spreadsheet, this would be the id of the\nspreadsheet. For clock events this returns null.\n\nReturn\n\n\n`String` --- the id of the entity in the publisher that this is a trigger for\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/script.scriptapp`\n\n*** ** * ** ***\n\n`get``Unique``Id()` \nReturns a unique identifier that can be used to distinguish triggers from each other.\n\nReturn\n\n\n`String` --- the unique identifier of the trigger\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/script.scriptapp`"]]