What is the type of e.values and e.oldValues, when reading boolean values?

70 Views Asked by At

Type of e.values differs markedly. Do we know the exact type that is returned in the event object of triggers for Boolean types?

1

There are 1 best solutions below

2
GSerraG On

Reading the cell by his coordinates , it return the correct values as you can see in this other table. Values of direct reading of cells

Table of values & type of values I got this values by clicking on checkboxes and triggering onEdit function. the values read are not boolean. in the table, you can see that the values read are TRUE/FALSE and string type. Reading the cell by his coordinates , it return the correct values as you can see in this other table. Values of direct reading of cells

you can test with this code

function onEdit(e) {
  var eA1 = e.range.getA1Notation();
  var ui = SpreadsheetApp.getUi();

  // e.value and his typeof
  ui.alert("(" + eA1 + ") e.value=" + e.value);
  ui.alert("(" + eA1 + ") typeof e.value=" + typeof e.value);

  // eValue and his typeof
  var eValue=e.value;
  ui.alert("reading of  eValue......");
  ui.alert("(" + eA1 + ") eValue=" + eValue);
  ui.alert("(" + eA1 + ") typeof eValue=" + typeof eValue);

  // getting de value of (e)cell
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var eTargetCell = sheet.getRange(eA1);
  var eCellValue = eTargetCell.getValue();

  // eCellValue and his typeof
  ui.alert("direct reading of cell.......");
  ui.alert("(" + eA1 + ") eValue=" + eCellValue);
  ui.alert("(" + eA1 + ") typeof eValue=" + typeof eCellValue);
}

You can easily make a function to get the boolean value of 'e' cell. To get the correct value of e.oldValue... you can recover it in the original cell, if needed, easily by

e.range.setValue(eOldValue);

or in another cell(not tested this point)