3

I am newbie google sheets and try to add trigger on updation but i received the error:

TypeError: Cannot read property "range" from undefined. (line 3, file "Code")

Code:

function onEdit(e){
    //Access the range with your parameter e.
    var range = e.range;
    var spreadSheet = SpreadsheetApp.openById("18AmVxMf8Q2oWvAsfh2KJ6hR-gC1FH6goul9Vocike1w");
    var column=e.range.getColumn();
    var row = e.range.getRow();
    var cell = e.range.getA1Notation();
    //do whatever you need with that range
    var allcolumns=[2,3];
    if(allcolumns.indexof(column)>-1){
        for (var i=column+1;i<column+2;i++){
            SpreadsheetApp.getactivesheet().getrange(row,i).setvalue(e.value);
        }
        SpreadsheetApp.getactivesheet().getrange(cell).setvalue('');
    }        
 }
Rubén
  • 34,714
  • 9
  • 70
  • 166
Abhay Narang
  • 31
  • 1
  • 2
  • 2
    How did you run the script? If you run the script at the script editor, such error occurs, because ``e`` is not defined. And your script supposes that the script is the container-bound script type. If the script is that, in order to work the trigger, can you try to edit the spreadsheet? By this, the trigger works and ``e`` of the event object is returned. But ``onEdit()`` is used as a simple trigger. So if you installed the trigger to ``onEdit()``, the function is run 2 times as a simple trigger and installable trigger. Please be careful this. – Tanaike Sep 19 '18 at 22:15
  • 1
    Does this answer your question? [TypeError: Cannot read property "source" from undefined](https://stackoverflow.com/questions/40288685/typeerror-cannot-read-property-source-from-undefined) – Rubén Jun 27 '20 at 03:24

0 Answers0