Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Input");
- var wscategories = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Filters_list");
- var categories = wscategories.getRange(103,1,12,13).getValues();
- var types = wscategories.getRange(123, 1, 22, 60).getValues();
- //This is just a test
- function tt(){
- Logger.log(categories[0]);
- var id = categories[0].indexOf("ÁGYAK");
- //var filteredCategories = categories.filter(function(o){return o [0] === "ÁGYAK"});
- //Logger.log(filteredCategories);
- var listToApply = categories.map (function (o) {return o[id] });
- Logger.log(listToApply);
- }
- function onEdit (e) {
- Logger.log("Inside on edit");
- var activeCell = e.range;
- var val = activeCell.getValue();
- var r = activeCell.getRow();
- var c = activeCell.getColumn();
- var wsName = activeCell.getSheet().getName();
- if (wsName == "Input" && c === 15 && r >= 4){
- Logger.log("applying validation rule");
- var catCol = categories[0].indexOf(val);
- Logger.log(categories[catCol]);
- var listToApply = categories.map (function (o) {return o[catCol] });
- //Remove first element as it is the column name on which we filter
- listToApply.shift();
- var cell = ws.getRange(r, c +1);
- applyValidationToCell(listToApply,cell);
- }
- if (wsName == "Input" && c === 16 && r >= 4){
- Logger.log("applying validation rule");
- var catCol = types[0].indexOf(val);
- Logger.log(categories[catCol]);
- var listToApply = types.map (function (o) {return o[catCol] });
- listToApply.shift();
- var cell = ws.getRange(r,c+1,1,3);
- applyValidationToCell(listToApply,cell);
- }
- }
- function applyValidationToCell(list,cell){
- var rule = SpreadsheetApp
- .newDataValidation()
- .requireValueInList(list)
- .setAllowInvalid(false)
- .build();
- cell.setDataValidation(rule);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement