Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What am I doing wrong when using onSelectionChange

I found this trigger onSelectionChange(e) on developers.google.com it should set background to red if a single empty cell is selected. I'm not getting that result with just copy and paste. I don't think I'm missing a step any help would be appreciated.

/**
 * The event handler triggered when the selection changes in the spreadsheet.
 * @param {Event} e The onSelectionChange event.
 */
function onSelectionChange(e) {
  // Set background to red if a single empty cell is selected.
  var range = e.range;
  if(range.getNumRows() === 1 
      && range.getNumColumns() === 1 
      && range.getCell(1, 1).getValue() === "") {
    range.setBackground("red");
  }
}
like image 922
william brewer Avatar asked Apr 24 '20 13:04

william brewer


2 Answers

UPDATE:

It seems it is fully rolled out to all users. You should be able to get it working without any modification to the code. The e, event object is similar to the onEdit event object.


onSelectionChange is a recently rolled out feature. Consider waiting a few days for the feature to be rolled out to your specific project and spreadsheet.

like image 70
TheMaster Avatar answered Oct 03 '22 06:10

TheMaster


Use the legacy runtime, not the V8 runtime. With V8 runtime in my case sometimes it is triggered, sometimes not. There are general problems with trigger executions in V8, see https://issuetracker.google.com/issues/147016387

like image 45
Michael Enke Avatar answered Oct 03 '22 07:10

Michael Enke