0
votes

I try to reproduce simple onEdit() example for Google Spreadsheets from that video:

https://www.youtube.com/watch?v=L1_nIhiVc5M&list=PLJnkyVAO-LM6VAUetaNIvwADp0XF-LlrE&index=85

I have a spreadsheet and script bound to it. I granted access to spreadsheet to the script. The script has the following code:

function onEdit(e) {
  Logger.log("something was edited " + e.old_value);
}

When I edit something in spreadsheet function executes but e is undefined. This is how result of execution looks in stackdriver:

stackdriver_screenshot

I feel that I miss something simple but I lost too many time trying to guess. Please show me what I'm doing wrong.

1
Typo. There is no property old_value in event e.See tag info page for official documentation or see your video again.TheMaster

1 Answers

0
votes

Answer:

The event object parameter you are trying to access is e.oldValue, not e.old_value.

More Information:

According to the documentation for Event Objects:

oldValue: Cell value prior to the edit, if any. Only available if the edited range is a single cell. Will be undefined if the cell had no previous content.

So in this case you can rectify this with a simple code change:

function onEdit(e) {
  Logger.log("something was edited " + e.oldValue);
}

I hope this is helpful to you!

References: