Skip to content

Object reference

Trigger

A ScriptApp.Trigger is one installed schedule or event rule in this project. ScriptApp.getProjectTriggers() returns only the installable triggers that belong to you, the user running the script. Use it to see which function a trigger runs, or delete a trigger with ScriptApp.deleteTrigger(). Other users must delete their own triggers.

ScriptApp.Trigger

Start here

Get this object first

List your installable triggers in this project, then look at the first one. You may have none, so check the length first.

Code.gs
function showFirstTriggerHandler() {
  const triggers = ScriptApp.getProjectTriggers();
  if (!triggers.length) {
    Logger.log('No installable triggers are associated with the current user in this project.');
    return;
  }
  Logger.log(triggers[0].getHandlerFunction());
}

Then use it

Common actions

Choose an action, then open its example only when you need the code.

List your handler functions and event types

Logs the function name and event type of each of your triggers.

ScriptApp.Trigger
Show example code
Code.gs
function logAllTriggerDetails() {
  const triggers = ScriptApp.getProjectTriggers();
  triggers.forEach((trigger) => {
    Logger.log(trigger.getHandlerFunction() + ' - ' + trigger.getEventType());
  });
}

Find your trigger by handler function name

Looks for one of your triggers that runs the chosen function and logs whether it found one.

ScriptApp.Trigger
Show example code
Code.gs
function findTriggerForFunction() {
  const functionName = 'sendWeeklySummary';
  const match = ScriptApp.getProjectTriggers().find((trigger) => {
    return trigger.getHandlerFunction() === functionName;
  });
  Logger.log(match ? 'Found a current-user trigger for ' + functionName : 'No current-user trigger found for ' + functionName);
}

Delete your triggers for one function (this removes triggers)

Deletes each of your triggers that runs the chosen function. Triggers that belong to other users are not deleted.

ScriptApp.Trigger
Show example code
Code.gs
function deleteTriggersForFunction() {
  const functionName = 'sendWeeklySummary';
  const triggers = ScriptApp.getProjectTriggers();
  let deletedCount = 0;
  triggers.forEach((trigger) => {
    if (trigger.getHandlerFunction() === functionName) {
      ScriptApp.deleteTrigger(trigger);
      deletedCount += 1;
    }
  });
  Logger.log('Deleted ' + deletedCount + ' current-user trigger(s) for ' + functionName);
}

Technical reference

Exact names and signatures

Open method details when you need them.

At a glance

Service
ScriptApp
Reference symbol
ScriptApp.Trigger
Object
Trigger
Runtime
From signature data

Methods and signatures

Browse 5 methods

getEventType

From signature data Google source
  • getEventType(): ScriptApp.EventType

getHandlerFunction

From signature data Google source
  • getHandlerFunction(): string

getTriggerSource

From signature data Google source
  • getTriggerSource(): ScriptApp.TriggerSource

getTriggerSourceId

From signature data Google source
  • getTriggerSourceId(): string

getUniqueId

From signature data Google source
  • getUniqueId(): string

Need the whole workflow?

Return to a task guide

Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.

Browse Triggers tasks