1

I'm trying to move an entire row to another sheet based on a specific value. See code below:

function onEdit(e) {
  const src = e.source.getActiveSheet();
  const r = e.range; 
  if (src.getName() == "Sheet1" && r.columnStart == 4 && r.getValue() == "TRUE") {
  const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
  src.getRange(r.rowStart,1,1,19).moveTo(dest.getRange(dest.getLastRow()+1,1,1,19));
  src.deleteRow(r.rowStart);
}
}

The function works when I delete the getValue part, since the script then basically runs on the fact that something is edited. But I'd like it to only work if the value is TRUE, hence the getValue.

Any idea why this is not working?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Niels Hahn
  • 13
  • 2

1 Answers1

2

getValue() returns a Javascript object, whose type is according to the type of value in the spreadsheet(=TYPE(D4))1.

Boolean TRUE in sheet is converted to javascript true. Try

&& r.getValue() === true 

Or just

&& r.getValue()

On the other hand, e.value is always provided as a string.

&& e.value === 'TRUE'
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • 1
    Thanks a lot, another lesson learned! Hopefully I can contribute to this community when I'm more experienced. – Niels Hahn Jul 05 '22 at 16:51