1
votes

I am new to programming, so bear with me here. I'm writing a script that, among other things, takes a cell value upon edit and then underlines a series of cells in various other ranges. The given cell has validation on it so that the user can only select from a range of options from a dropdown menu.

The validation function works fine from what I can tell, but when I edit the designated cell by selecting one of the dropdown menu options, nothing happens. Do I need to call the onEdit(e) function? I've read the api references and searched stackoverflow and the web for help, but I'm stuck.

Please advise; any help is appreciated. Here is the relevant part of my code:

function validateLeagueSizeInput(sheet) {
  var cell = sheet.getRange('G2'),
      values = [[8], [10], [12]],
      range = sheet.getRange('A998:A1000').setValues(values),
      rule = SpreadsheetApp.newDataValidation().requireValueInRange(range, true).build();
  cell.setDataValidation(rule);
}

function onEdit(e) {
  var cell = e.value,
      range = SpreadsheetApp.getActiveSheet().getRange('A2:F301');
  for (var i = cell + 1; i < Math.floor(301 / cell); i += cell) {
    for (var j = 1; j <= 6; j++) {
      range[i][j].setBorder(null, null, true, null, null, null);
    }
  }
}
1
"hard code" a value for the variable cell -> var cell = 5;. Then set a break point and run the debugger. Link to Google Documentation - Troubleshooting Step through the code. If you are not sure if the onEdit() function is running, add a Logger.log('it ran! ' + e.value); statement at the top, edit a cell, then VIEW the LOGS. - Alan Wells
Thanks for the advice, @SandyGood! I had tried logging the cell variable previously, and the onEdit(e) function is definitely not being triggered. It could be that options selected from a drop down menu do not trigger the onEdit() function, as @Mogsdad has eluded. - Michael Stromberg
Try an installed change trigger event. - Alan Wells
Thanks again for the input. I decided to just create a menu item and have the code execute when triggered that way. - Michael Stromberg

1 Answers

2
votes

There are plenty of Spreadsheet changes that don't trigger onEdit() functions - you may just be the first person to report this particular one. See Detect user inserting row or column in a google spreadsheet and reacting in a script.