0

Google Apps Script - triggered onEdit(e) with onEdit and oChange, both returned same error.

TypeError: Cannot read property 'range' of undefined code 6 ie; e.range

function onEdit(e) {
 
  var range = e.range;
  var spreadSheet = e.source;
  var sheetName = spreadSheet.getActiveSheet().getName();
  var row = range.getRow();  
  
  if(sheetName == 'DATA')
  {
    var new_date = new Date();
    spreadSheet.getActiveSheet().getRange(row,6).setValue(new_date).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P"); 
  }
}

`

Using SpreadSheet with 6 columns, the Col6 (F) for update (MM/DD/YYYY hh:mm:ss A/P) triggered with onedit. Tried necessary changes on colA to colE, but Col6 (F) not updating the for any changes.

Please note: for empty cell running the script, property return error due to "null" value is understood. But here even the changes made on SS does not return the UPDATE on col6(F). Kindly HELP

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
LPCPTest
  • 1
  • 2

1 Answers1

0

This is working for me:

function onEdit(e) {
  e.source.toast('Entry')
   const sh = e.range.getSheet();  
  if(sh.getName() == 'Sheet0') {
    e.source.toast('Gate1')
    var new_date = new Date();
    sh.getRange(e.range.rowStart,6).setValue(new_date).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P"); 
  }
}

But you don't have any logic to control where you wish to monitor the ranges it just triggers on any edits to a given page.

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Thanks for your prompt help, but please to refer that we did not intend the TOAST popup (temporary), Indeed we want an any edit or change in value of cell of each row (ColA:ColE) that has to be updated in same row at Col6. If you wish, I may enable the link to the SS for your link (Public) for the time being – LPCPTest Nov 15 '22 at 20:33
  • Yeah well you can easily remove them. I use them for debugging purposes. – Cooper Nov 15 '22 at 20:33
  • https://docs.google.com/spreadsheets/d/11JWG8CD0d8B6gsAns2y39yT9k87syReA09P3wzuqaiA/edit?usp=sharing – LPCPTest Nov 15 '22 at 21:15
  • Sorry but I don't follow links to spreadsheets – Cooper Nov 15 '22 at 21:31