Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

javascript - Google Sheets onEdit(e) TypeError: cannot read property

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."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ....


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...