Google Apps Script

Understanding Events

An event is an action that happens when the state of an object changes. Google Apps Script can detect the events in the list below, and you can write code that will execute in response to those events. A resource that allows you to detect and respond to an event is called a trigger. For more information, see Understanding Triggers.

Here is a list of all currently available events:

  • Clock tick events
  • Script/add-on installation events
  • Spreadsheet open events
  • Spreadsheet change events
  • Spreadsheet edit events
  • Spreadsheet form submit events
  • Form editor open events
  • Form submit events
  • Document open events

Events in more detail

A function is passed an event parameter when it is invoked in response to an event. That event parameter contains the information about the event. For example, below is a function that is triggered when a Spreadsheet is edited. It uses the e parameter to access the cell that was edited and add a timestamp.

function onEdit(e) {
  e.range.setComment("Edited at: " + new Date().toTimeString());
}

Here are tables that you can use as a reference for the information passed into a function for each type of event.

Clock Events

Name Example Notes How to access
authMode FULL A value from the ScriptApp.AuthMode enum e.authMode
year 2010 e.year
month 12 between 1-12 e.month
day-of-month 31 one-based e["day-of-month"]
day-of-week 7 Monday is day 1, Sunday is day 7 e["day-of-week"]
week-of-year 23 e["week-of-year"]
hour 23 between 0-23 e.hour
minute 59 e.minute
second 59 e.second
timezone UTC This timezone value applies to the other date- and time-related parameters of the clock event. e.timezone

Script/Add-on Installation Events

Name Example Notes How to access
authMode FULL A value from the ScriptApp.AuthMode enum e.authMode

Spreadsheet Open Events

Name Example Notes How to access
authMode LIMITED A value from the ScriptApp.AuthMode enum e.authMode
source Spreadsheet Always returns a Spreadsheet object e.source
user john@example.com Always returns a User object, representing the owner of the Spreadsheet e.user

Spreadsheet Change Events

Name Example Notes How to access
authMode FULL A value from the ScriptApp.AuthMode enum e.authMode
changeType INSERT_ROW The type of change event. Possible values are EDIT, INSERT_ROW, INSERT_COLUMN, REMOVE_ROW, REMOVE_COLUMN, INSERT_GRID, REMOVE_GRID, OTHER e.changeType
user bill@example.com Always returns a User object, representing the owner of the Spreadsheet e.user

Spreadsheet Edit Events

Name Example Notes How to access
authMode LIMITED A value from the ScriptApp.AuthMode enum e.authMode
user bill@example.com Always returns a User object, representing the owner of the Spreadsheet e.user
source Spreadsheet Always returns a Spreadsheet object e.source
range Range Always returns a Range object e.range
value 10 Only available if the edited range is a single cell e.value

Spreadsheet Form Submit Events

Name Example Description How to access
authMode FULL A value from the ScriptApp.AuthMode enum e.authMode
values ["2010/03/12 15:00", "bob@example.com", "Bob", "27", "Bill", "28", "Susan", "25"] Array with values in the same order as they appear in the Spreadsheet. e.values
range Range Always returns a Range object e.range
namedValues {'First Name': ['Jane'], 'Timestamp': ['6/7/2012 20:54:13'], 'Last Name': ['Doe']} An object containing the question names and values from the form submission. e.namedValues

Form Editor Open Events

Name Example Notes How to access
authMode LIMITED A value from the ScriptApp.AuthMode enum e.authMode
user john@example.com Always returns a User object, representing the owner of the form. Note that this event does not occur when a user opens a form to respond, but rather when an editor opens the form to modify it. e.user

Form Submit Events

Name Example Description How to access
authMode FULL A value from the ScriptApp.AuthMode enum e.authMode
response FormResponse Always returns a FormResponse object e.response

Document Open Events

Name Example Notes How to access
authMode LIMITED A value from the ScriptApp.AuthMode enum e.authMode
source Document Always returns a Document object e.source
user john@example.com Always returns a User object, representing the owner of the document e.user

Authentification requise

Vous devez être connecté à Google+ pour effectuer cette opération.

Connexion en cours…

Le site Google pour les développeurs a besoin de votre autorisation pour effectuer cette opération.