get value from Range in Custom function returns "#ERROR!" during Loading

177 Views Asked by At

I have a spreedsheet where I want to have a unique id for the row, I use the Utilities method getUuid.

I don´t want it to get the Utilities.getUuid() method when insertion of a row happens, so I want to get the value from the cell where the insertion has been made and check if it's empty then generate a new uuid if not, do nothing.

function uuid() {
  const ss = SpreadsheetApp.getActive();
  const sheet = ss.getActiveSheet();
  const activeRange = sheet.getActiveRange();
 
  const val = activeRange.getValue();
  Logger.log(val)  

  if(!val) {
    return Utilities.getUuid();
  }
}

What steps will reproduce the problem?

  1. Spreadsheet with values at least 2 rows and 2 cols
  2. col #2 has the =uuid(true) in order to calculate the uuid

What is the expected output?

  1. After the insertion of a row in between the two rows, the row below should not change the uuid
  2. The logger of the val should retrieve the value but it shows #ERROR!
0

There are 0 best solutions below