Spreadsheet & Formula Studio

Apps Script onEdit Not Running: Simple vs Installable

Why onEdit does not fire or cannot send mail: the limits of simple triggers, why formula changes do not trigger it, and when to use an installable trigger.

PerkTonic Team3 min read
Cover of the guide "Apps Script onEdit Not Running: Simple vs Installable"

Your onEdit function does not fire, or it fails the moment it tries to send an email. The cause is usually the type of trigger: a function named onEdit runs as a simple trigger, and simple triggers cannot use services that need authorisation, such as mail. An installable on-edit trigger removes that limit, and the Apps Script Automation Generator lets you choose it when you generate the script.

Simple and installable on-edit triggers

A simple trigger is a function with a reserved name. Name a function onEdit and Google runs it after a user edits the sheet, with no setup. That convenience has limits:

  • It cannot use services that need authorisation, so MailApp and GmailApp calls fail.
  • It runs with the permissions of the person who edited, who may have no rights to what the script touches.
  • It has a short time limit, and a script that runs long is stopped.
  • The function name must be exactly onEdit. A different spelling, even in letter case, never fires.

An installable on-edit trigger is created in Apps Script and attached to a function with any name. You authorise it once, and it runs with the permissions of the account that created it, so it can send mail. Google documents both types: see simple triggers and installable triggers.

Why a formula change does not trigger onEdit

onEdit fires when a person changes a cell by typing, pasting or filling. It does not fire when a value changes because a formula recalculated. If cell D2 turns into "Done" because of an IF formula, nothing is triggered, although the cell shows a new value.

The same holds for changes made by another script or by an import. If a sheet is filled by IMPORTRANGE, by the API or by a form, check whether a different trigger fits, such as one for form submissions. Where the status must be a formula, you can watch the cells it depends on instead. If those are typed by people, an on-edit trigger on them will fire.

Test your function by typing a value by hand in the watched cell. If it works then and not when a formula changes the value, you have found the cause.

Choosing the trigger in the generator

The generator offers these triggers:

  • simple onEdit
  • installable on-edit
  • hourly, daily or weekly
  • form submit
  • onOpen menu
Trigger picker in the Apps Script Automation Generator showing simple onEdit and installable on-edit
The picker offers a simple onEdit and an installable on-edit trigger.

For a script that sends mail or touches other files, pick installable on-edit. For a small change inside the sheet, such as a timestamp, a simple onEdit is enough. A time-based schedule is described in Run a Google Apps Script Every Hour.

With an installable trigger, the generated script comes with installation steps: create the trigger in Apps Script and authorise it.

Installation steps with the create trigger step marked in the Apps Script Automation Generator
The installable trigger comes with a step that creates the trigger.

The full example, an email when a status becomes Done, is in Send an Email When a Google Sheets Cell Changes. Every script is also syntax-checked on the server, and an error is reported with the line number, so a typo in the code is found before you paste it.

Permissions the script asks for

When you authorise a script, Google lists what it can do. The generator shows the same list earlier, in Permissions it will ask for. The permissions are detected from the services the script uses: SpreadsheetApp for the sheet, GmailApp or MailApp for mail, and others for other services.

Permissions list in the Apps Script Automation Generator with the MailApp send mail permission marked
The permissions list shows the mail permission that the script needs.

Check the list against your task. A script that only fills a date should ask for access to the spreadsheet and nothing else. If MailApp or GmailApp appears and you did not ask for mail, change the task and generate again. For a simple trigger, a script that uses these services will not work, which is the reason to use the installable type.

If a trigger exists but does not run, open the trigger list in Apps Script and check the executions for an error. A typical cause is that the authorisation expired or that the trigger belongs to an account that no longer has access to the sheet.

Check your own file

Open the Apps Script Automation Generator, describe your task and pick installable on-edit if the script sends mail or uses another service. Install the trigger, authorise it, and test by typing a value by hand in the watched cell.

Was this guide helpful?
Share

Comments