Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Input");
  2. var wscategories = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Filters_list");
  3. var categories = wscategories.getRange(103,1,12,13).getValues();
  4. var types = wscategories.getRange(123, 1, 22, 60).getValues();
  5.  
  6. //This is just a test
  7. function tt(){
  8. Logger.log(categories[0]);
  9. var id = categories[0].indexOf("ÁGYAK");
  10. //var filteredCategories = categories.filter(function(o){return o [0] === "ÁGYAK"});
  11. //Logger.log(filteredCategories);
  12. var listToApply = categories.map (function (o) {return o[id] });
  13. Logger.log(listToApply);
  14. }
  15.  
  16. function onEdit (e) {
  17. Logger.log("Inside on edit");
  18. var activeCell = e.range;
  19. var val = activeCell.getValue();
  20. var r = activeCell.getRow();
  21. var c = activeCell.getColumn();
  22. var wsName = activeCell.getSheet().getName();
  23. if (wsName == "Input" && c === 15 && r >= 4){
  24. Logger.log("applying validation rule");
  25. var catCol = categories[0].indexOf(val);
  26. Logger.log(categories[catCol]);
  27. var listToApply = categories.map (function (o) {return o[catCol] });
  28. //Remove first element as it is the column name on which we filter
  29. listToApply.shift();
  30. var cell = ws.getRange(r, c +1);
  31. applyValidationToCell(listToApply,cell);
  32.  
  33.  
  34. }
  35.  
  36.  
  37. if (wsName == "Input" && c === 16 && r >= 4){
  38. Logger.log("applying validation rule");
  39. var catCol = types[0].indexOf(val);
  40. Logger.log(categories[catCol]);
  41. var listToApply = types.map (function (o) {return o[catCol] });
  42. listToApply.shift();
  43. var cell = ws.getRange(r,c+1,1,3);
  44. applyValidationToCell(listToApply,cell);
  45. }
  46. }
  47.  
  48. function applyValidationToCell(list,cell){
  49.  
  50.  
  51. var rule = SpreadsheetApp
  52. .newDataValidation()
  53. .requireValueInList(list)
  54. .setAllowInvalid(false)
  55. .build();
  56.  
  57.  
  58. cell.setDataValidation(rule);
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement