A function named onEdit is a simple trigger. Once the project is saved, Sheets runs it every time someone edits a cell, with no setup. It receives an event object, usually called e:
- e.range is the edited cell. getSheet().getName(), getRow() and getColumn() tell you where it is.
- e.value is the new value and e.oldValue the previous one, both as text. A ticked checkbox arrives as "TRUE", not the boolean true.
- e.source is the spreadsheet, for reaching other tabs.
onEdit runs for every edit in the whole file, so start with guard clauses: if the edit is not on the right tab, column or row, return before doing anything. Without them, a header change or an edit on another tab sets off your code too.
Simple triggers can't do things that need your permission, such as sending email; that needs an installable trigger, in the next lesson. In this practice copy, the edits you make in the grid run your saved onEdit, and the checker plays a set of edits through it.
Guard clauses first, then the work for the one edit that matters.