1
votes

I'm trying to implement the onEdit(e) simple trigger of Google Sheets. Everytime I try execute even a simple function such as:

function onEdit(e){
  Logger.log(e.oldValue);
}

I get the following error:

enter image description here

My step by step: enter image description here

I've tried following these two videos with no success:

https://www.youtube.com/watch?v=eWn_JxPSbds

https://www.youtube.com/watch?v=L1_nIhiVc5M


EDIT: SOLUTION

Thanks to @JPV and @TheMaster for the two potential solutions:

I was viewing the "Logs" and not the "Stackdriver Logging".

It seems you need to disable the V8 to view it in Logs, but need the Stackdriver Logging to view it with V8.

At least that seems to be the case with me

EDIT TWO

Here's the documentation where the issue is addressed:

https://developers.google.com/apps-script/guides/v8-runtime#ui_changes_for_logging

"If your script uses the Rhino runtime, selecting View > Logs in the Apps Script editor only shows you recent logs written by the Logger service. You must select View > Stackdriver Logging to see logs written with the console class."

2
Run this logger statement: Logger.log(JSON.stringify(e)). It will return all the event objects and their values. It's a little hard to tell, but I'm assuming that the edited cell DID have previous value.Tedinoz
@Tedinoz Yes it did. Still getting an error of: [20-03-04 14:20:18:487 SAST] null. And if I change the "e" to something like "e.oldValue" it's undefined.Michael Tolsma
Did you enable the V8 runtime? If so, try switching back to Rhino (by disabling V8) and see if it then works?JPV
Sorry, I wasn't as clear as i should have been. rem out your logger statement and substitute `Logger.log(JSON.stringify(e)). This will display ALL the event objects, including the oldValue. Include that result in your question or in a comment.Tedinoz
@JPV how do I disable V8? It is currently enabledMichael Tolsma

2 Answers

4
votes

Nothing is wrong with V8. That error is because you ran the script directly by clicking run button before. That caused the error and was logged. When you edit, it is logged to view>stackdriver logging. But the previous error is shown to you. You're looking at old logs.

As per the official documentation,

For scripts using the V8 runtime, the script editor View > Logs menu item shows both Logger and console results for the most recent execution in the current session

Only current session logs is available to View>Logs. To access previous session logs or logs logged not by running a function directly in the current session, use View > Stackdriver Logging ....

1
votes

This seems to be a glitch in the new V8 engine. Disabling V8 should fix it. Let's hope this will be fixed soon.