1

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: enter image description here

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) enter image description here

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?

6
  • If by "when I run the script" you mean that you click the Run button from the Google Apps Script editor toolbar, the error occurs because the script editor doesn't assigns an object to the function parameter. This is very comment problem that has being asked multiple times. By the other hand it's not clear if this is a bounded script or a stand alone script, among other missing details.
    – Rubén
    Mar 17 at 20:40
  • Searching TypeError: Cannot read properties of undefined is:question isanswered:1 returns 4 answered questions. If you need fuerther help review these questions, if you still need need help, edit your quetion to add a brief but complete description of you Google Apps Script project including the steps to reproduce the error and the relevant parts of the bounded spreasheet, show what you have tried to solve the problem by yourself.
    – Rubén
    Mar 17 at 20:47
  • By the way, this is an edge question as is about an online IDE and the error is related to JavaScript and to programming concepts. Stack Overflow has many, many times more questions about this error.
    – Rubén
    Mar 17 at 20:56
  • 1
    The onEdit(e) function is a simple trigger that is designed to run automatically when you manually edit the spreadsheet. In that context, the event object e is properly populated. Do not run the code through the ▷ Run button in the script editor. If you do, the event parameter e is not populated, causing the error you mention. Mar 18 at 9:23
  • 1
    The 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. Mar 18 at 14:55

1 Answer 1

1

The trigger list shown in the question tells that there is an installable trigger that runs on every change to the spreadsheet. The event object of this type of trigger lacks the source and range fields the code attempts to reference.

The onEdit(e) function is a simple trigger that runs automatically when the spreadsheet is manually edited without installing any triggers separately. Its event object includes the necessary fields.

To avoid the issue you describe, simply delete the installable trigger you have created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.