Hello everyone.
I am a beginner at using apps script in google sheets and I am trying to bring a drop down to a whole column from a particular list. The data validation works on the basis of the title of the sheet, executing setdatavalidation() to all cells through a for loop.
If the cell of column = 3 and row = 2 in a sheet contains the company name, then through apps script it will execute, first, a filter on a range from the sheet containing the product lists of different companies, based on the first column,i.e. company name. The 2nd column is the actual product list that should come in the drop down. Next, I execute the map function, mapping the values of 2nd column in a variable and then setting the DataValidation of each cell in the 2nd column.
My code works when the products of a company are less than 500, but when they are greater than that it doesn't execute the code. I'll paste the code below and would love to have a solution for this issue.
var fbk = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FBK");
var ts = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Product lists");
var tsOptions=ts.getRange(3, 1, ts.getLastRow()-2,2).getValues();
function myFunction() {}
function onEdit(e){
var activeCell = e.range;
var val = activeCell.getValue();
var r = activeCell.getRow();
var c = activeCell.getColumn();
var ssName = activeCell.getSheet().getName();
if(ssName == "FBK" && c ==3 && r==2){
for(var i=4;i < 3000;i++){
var filteredOptions = tsOptions.filter(function(o){return o[0] === val});
var listToApply = filteredOptions.map(function(o){return o[1]});
console.log(listToApply);
var cell = fbk.getRange(i,2);
applyValidationToCell(listToApply,cell);
}
}
}
function applyValidationToCell(list,cell)
{
var rule = SpreadsheetApp
.newDataValidation()
.requireValueInList(list)
.setAllowInvalid(false)
.build();
cell.setDataValidation(rule);
}
Hope I have given you all the information.
Thank You!