I am trying to write a google apps script that updates an existing data validation rule to toggle the "Show dropdown list in cell" option. I have it mostly working, it does change the "Show dropdown list in cell" option, however it is not retaining the original criteria range, which is on a different sheet. It appears to be changing the range to use the sheet the validation rule was from instead of the other sheet. The original data validation requires a value in the range Sheet2!A2:A
, but when I run the below script, it changes to require a value in the range Base!A2:A
instead.
function turnOffDropDown() {
var baseSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Base");
var templateRange = baseSheet.getRange("B2");
var rule = templateRange.getDataValidation();
var criteria = rule.getCriteriaType();
var args = rule.getCriteriaValues();
args[1] = false;
var newRule = rule.copy().withCriteria(criteria, args).build();
templateRange.setDataValidation(newRule);
}
Am I doing something wrong that it isn't retaining the original range, is there a way to specify the range I want on Sheet2, or is there a different way to update the "Show dropdown list in cell" option?