0

I have a very simply code;

function onEdit(e){
  
  var ss = e.source.getActiveSheet();
  
  ss.getRange(1,1).setValue(89);
  
}

When I run this, I get the error message

"TypeError: Cannot read property 'source' of undefined (line 3, file "Code")"

However, the code does, what it is supposed to do, that is, it works. I go on to the spreadsheet, type anything anywhere, and get 89 on the cell A1.

Why the error and how to make sure I don't get one?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Eli
  • 41
  • 7
  • What are you passing in to `onEdit` as `e`? Is this Google Apps Script? It looks like it is. – shreyasm-dev Oct 12 '20 at 15:56
  • It is Google Apps Script. Not sure, how to answer your question. – Eli Oct 12 '20 at 16:03
  • Since it's Google Apps Script, I've suggested an edit to add that tag into the question. – shreyasm-dev Oct 12 '20 at 16:04
  • 1
    I'm guessing that you tried to run the function from the script editor. You cannot do that unless you provide the event object in the form as shown [here](https://developers.google.com/apps-script/guides/triggers/events#edit) – Cooper Oct 12 '20 at 16:16

0 Answers0