Simple triggers and
installable triggers let Apps Script
run a function automatically if a certain event occurs. When a trigger fires,
Apps Script passes the function an event object as an argument, typically called
e. The event object contains information about the context that caused the
trigger to fire. For example, the sample code below shows a simple onEdit(e)
trigger for a Google Sheets script that uses the event object to determine which
cell was edited.
function onEdit(e){
// Set a comment on the edited cell to indicate when it was changed.
var range = e.range;
range.setNote('Last modified: ' + new Date());
}
This page details the fields in the event object for different types of triggers.
Google Sheets events
The various Google Sheets-specific triggers let scripts respond to a user's actions in a spreadsheet.
Open(simple and installable) |
|
|---|---|
authMode |
A value from the LIMITED |
source |
A Spreadsheet |
user |
A [email protected] |
Change(installable) |
|
|---|---|
authMode |
A value from the FULL |
changeType |
The type of change ( INSERT_ROW |
user |
A [email protected] |
Edit(simple and installable) |
|
|---|---|
authMode |
A value from the LIMITED |
user |
A [email protected] |
source |
A Spreadsheet |
range |
A Range |
value |
New cell value after the edit. Only available if the edited range is a single cell. 10 |
oldValue |
Cell value prior to the edit, if any. Only available if the edited range is a single cell. Will be undefined if the cell had no previous content. 1234 |
Form submit(installable) |
|
|---|---|
authMode |
A value from the FULL |
values |
Array with values in the same order as they appear in the spreadsheet ['2015/05/04 15:00', '[email protected]', 'Bob', '27', 'Bill', '28', 'Susan', '25'] |
range |
A Range |
namedValues |
An object containing the question names and values from the form submission {
'First Name': ['Jane'],
'Timestamp': ['6/7/2015 20:54:13'],
'Last Name': ['Doe']
}
|
Google Docs events
Triggers allow Google Docs to respond when a user opens a document.
Open(simple and installable) |
|
|---|---|
authMode |
A value from the LIMITED |
source |
A Document |
user |
A [email protected] |
Google Forms events
The Google Forms-specific triggers let scripts respond when a user edits a form or submits a response.
Open* (simple and installable) |
|
|---|---|
authMode |
A value from the LIMITED |
source |
A Form |
user |
A [email protected] |
* This event does not occur when a user opens a form to respond, but rather when an editor opens the form to modify it.
Form submit(installable) |
|
|---|---|
authMode |
A value from the FULL |
response |
A FormResponse |
source |
A Form |
Add-on events
The onInstall() trigger runs
automatically when a user installs an add-on.
Install(simple) |
|
|---|---|
authMode |
A value from the FULL |
Time-driven events
Time-driven triggers (also called clock triggers) let scripts execute at a particular time or on a recurring interval.
| Time-driven (installable) | |
|---|---|
authMode |
A value from the FULL |
year |
The year 2015 |
month |
Between 12 |
day-of-month |
Between Because this property name contains dashes it must be accessed via
31 |
day-of-week |
Between Because this property name contains dashes it must be accessed via
7 |
week-of-year |
Between Because this property name contains dashes it must be accessed via
52 |
hour |
Between 23 |
minute |
Between 59 |
second |
Between 59 |
timezone |
The timezone UTC |