I'm trying to add the current date to a cell in column K when any cell in that respective row is changed.
I found this script and altered it for my situation so I can deploy it as a trigger:
function onEdit(e) {
var sh = e.source.getActiveSheet();
if (sh.getName() !== 'pipeline' || e.range.columnStart == 1 || e.range.columnStart > 10 || e.range.rowStart < 6) return;
sh.getRange(e.range.rowStart, 11).setValue(new Date())
}
As you can see I'm searching for tab named pipeline
, which exists, it's the 3rd tab in my target sheet.
However, when I click the Google Apps Script Editor "Run" button I get:
TypeError: Cannot read properties of undefined (reading 'source')
Instead of editing the code, I also tried going to my target sheet pipeline
and made some changes. When I then check the trigger itself I see that it's being executed but with errors:
I then inspect the errors (they're all the same) and see
TypeError: Cannot read properties of undefined (reading 'columnStart') at onEdit(Code:3:48)
I read multiple articles recommended by Rubén below, but none of them seems to address my issue (e.g. they address a mismatch in cell values, which I'm not checking for and using forms which I'm not using).
From what I can derive from the error, initially I thought the e
parameter was not found, but sh.getName()
check is passed, so e
seems to be fine.
But I don't see why e.range.columnStart
seems to fail.
What am I doing wrong?
onEdit(e)
function is a simple trigger that is designed to run automatically when you manually edit the spreadsheet. In that context, the event objecte
is properly populated. Do not run the code through the ▷ Run button in the script editor. If you do, the event parametere
is not populated, causing the error you mention.onEdit(e)
function is a simple trigger. You should delete the installable trigger you have created. The event object of the "on change" trigger lacks the fields you are trying to reference.