TriggerShelf

Error fix

Fix "Cannot read properties of undefined (reading 'range')" in onEdit

Trigger: Simple onEditServices: SpreadsheetAppMock-tested: Nov 2026

Cannot read properties of undefined (reading 'range')

The event object e only exists when a trigger fires. Press Run in the editor and e is undefined. Guard for it, and test with a fake event.

Set it up

  1. Add if (!e || !e.range) return at the top of your handler.
  2. Use testOnEdit to run your logic by hand.
  3. Test the real thing by editing a cell, then open Executions.

The script

/**
 * Fix: "Cannot read properties of undefined (reading 'range')".
 * The event object only exists when a trigger fires. Running onEdit from the editor
 * passes nothing, so guard for it and keep a manual test function.
 */
function onEdit(e) {
  if (!e || !e.range) return 'no-event';
  return 'edited:' + e.range.getA1Notation();
}

function testOnEdit() {
  var sheet = SpreadsheetApp.getActiveSheet();
  return onEdit({ range: sheet.getRange('A2'), value: 'test' });
}
Test status. 3 of 3 automated checks pass, run Nov 2026 against simulated Google services. This recipe has not yet been run inside a live Google account. Test it on a copy of your sheet first.

What you should see

ExecutionResult
Run onEditno-event
Edit A2edited:A2

Run from the editor now returns no-event instead of throwing. Sample values, not output from a real account.

Common errors and fixes

It works when I edit but fails on Run
That is expected. Run passes no event.
e.range is undefined in a time-driven trigger
Time-driven triggers pass a different event. Read the sheet directly.

Permissions. Running this script asks you to grant Google permissions for the services listed above, to your own script. TriggerShelf never receives your Google data. See the permissions table. Google will show "Google hasn't verified this app"; that is expected for a script you paste yourself.