Introduction to Triggers

Triggers are the backbone of automation in Apps Script. Instead of running a function manually, triggers automatically execute your code in response to an event — a user opening a sheet, editing a cell, submitting a form, or a scheduled time being reached.

Types of Triggers

Simple Triggers

Simple triggers are reserved function names that Apps Script automatically invokes when a matching event occurs. No setup is required — just name your function correctly:

Function NameFires When
onOpen(e)A spreadsheet, doc, or form is opened
onEdit(e)A cell is edited in a spreadsheet
onFormSubmit(e)A Google Form is submitted
onSelectionChange(e)The cell selection changes

Simple triggers run with limited permissions and cannot send emails, access external services, or modify files outside the current document.

Installable Triggers

Installable triggers offer more power — they run with the full permissions of the user who created them and can fire on the same events as simple triggers plus time-based schedules.

They must be set up either through the Apps Script UI (Triggers menu) or programmatically using ScriptApp.

Simple Trigger Example

// Runs automatically whenever the spreadsheet is opened function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu("Sales Tools") .addItem("Send Weekly Digest", "sendWeeklyDigest") .addItem("Refresh Dashboard", "refreshDashboard") .addToUi(); }

Installable Trigger Example

// Set this up once — it then runs every day at 8am function createDailyReportTrigger() { ScriptApp.newTrigger("sendDailyReport") .timeBased() .everyDays(1) .atHour(8) .create(); Logger.log("Daily report trigger created."); } function sendDailyReport() { var sheet = SpreadsheetApp .getActiveSpreadsheet() .getSheetByName("Sales Tracker"); var lastRow = sheet.getLastRow(); Logger.log("Daily report: " + lastRow + " total rows in Sales Tracker."); // Add your reporting or email logic here }

Choosing Between Simple and Installable

Simple TriggersInstallable Triggers
Setup requiredNoneYes (script or UI)
Email/external accessNoYes
Time-based schedulingNoYes
Run asCurrent user (limited)Trigger owner
Timeout30 seconds6 minutes

The Event Object

Most trigger functions receive an event object e with context about what happened:

function onEdit(e) { Logger.log("Edited cell: " + e.range.getA1Notation()); Logger.log("Old value: " + e.oldValue); Logger.log("New value: " + e.value); Logger.log("Sheet: " + e.source.getActiveSheet().getName()); }

For the Sales Tracker, e.range tells you exactly which cell was changed, e.value gives the new value, and e.oldValue gives what was there before.