A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/apps-script/guides/triggers below:

Simple Triggers | Apps Script

Simple Triggers

Stay organized with collections Save and categorize content based on your preferences.

Triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. Simple triggers are a set of reserved functions built into Apps Script, like the function onOpen(e), which executes when a user opens a Google Docs, Sheets, Slides, or Forms file. Installable triggers offer more capabilities than simple triggers but must be activated before use. For both types of triggers, Apps Script passes the triggered function an event object that contains information about the context in which the event occurred.

Note: For information on how to use triggers in Google Workspace add-on projects, see Triggers for Google Workspace add-ons. Getting started

To use a simple trigger, simply create a function that uses one of these reserved function names:

The e parameter in the function names above is an event object that is passed to the function. The object contains information about the context that caused the trigger to fire, but using it is optional.

Restrictions

Because simple triggers fire automatically, without asking the user for authorization, they are subject to several restrictions:

These restrictions do not apply to doGet(e) or doPost(e).

onOpen(e)

The onOpen(e) trigger runs automatically when a user opens a spreadsheet, document, presentation, or form that they have permission to edit. (The trigger does not run when responding to a form, only when opening the form to edit it.) onOpen(e) is most commonly used to add custom menu items to Google Sheets, Slides, Docs, or Forms.

onInstall(e)

The onInstall(e) trigger runs automatically when a user installs an Editor add-on from within Google Docs, Sheets, Slides, or Forms. The trigger won't run when a user installs the add-on from the Google Workspace Marketplace website. Note that there are certain restrictions on what onInstall(e) can do, learn more about authorization. The most common use of onInstall(e) is simply to call onOpen(e) to add custom menus. After all, when an add-on is installed, the file is already open, and thus onOpen(e) doesn't run on its own unless the file is reopened.

onEdit(e)

The onEdit(e) trigger runs automatically when a user changes the value of any cell in a spreadsheet. Most onEdit(e) triggers use the information in the event object to respond appropriately. For example, the onEdit(e) function below sets a comment on the cell that records the last time it was edited.

Note: The onEdit() trigger only queues up to 2 trigger events. onSelectionChange(e)

The onSelectionChange(e) trigger runs automatically when a user changes the selection in a spreadsheet. To activate this trigger, you must refresh the spreadsheet once the trigger is added and every time the spreadsheet is opened.

If the selection moves between multiple cells in a short time, some selection change events might be skipped to reduce latency. For example, if many selection changes are made within two seconds of each other, only the first and last selection changes will activate the onSelectionChange(e) trigger.

In the example below, if an empty cell is selected, the onSelectionChange(e) function sets the cell’s background to red.

doGet(e) and doPost(e)

The doGet(e) trigger runs automatically when a user visits a web app or a program sends an HTTP GET request to a web app. doPost(e) runs when a program sends an HTTP POST request to a web app. These triggers are demonstrated more in the guides to web apps, HTML service, and Content service. Note that doGet(e) and doPost(e) are not subject to the restrictions listed above.

Available types of triggers

If the restrictions on simple triggers keep them from meeting your needs, an installable trigger might work instead. The table below summarizes which types of triggers are available for each type of event. For example, Google Sheets, Slides, Forms, and Docs all support simple open triggers, but only Sheets, Docs and Forms support installable open triggers.

* The open event for Google Forms does not occur when a user opens a form to respond, but rather when an editor opens the form to modify it.

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 2025-08-04 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 2025-08-04 UTC."],[[["Apps Script triggers automate functions based on events like opening a document or editing a cell."],["Simple triggers are pre-built functions with limitations, while installable triggers offer more control but require setup."],["`onOpen()`, `onEdit()`, `onInstall()`, and `onSelectionChange()` are common simple triggers with specific use cases."],["Triggers receive an event object with details about the triggering action."],["For advanced automation and authorization, consider installable triggers."]]],[]]


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