I'm building a data validation rule for a cell in my spreadsheet via Apps Script. It should check that date is today or before, and when user clicks on the cell date picker should appear. It's possible to do so via GUI interface, but I can't figure out how to do it from the Apps Script.
I've tried using requireDateOnOrBefore
, but it only worked for fixed date, so if the rule is created today (16.02), tomorrow it will still check against 16.02, not 17.02.
I've tried using requireFormulaSatisfied
, but then the date picker doesn't appear on click.
Following Tom Sharpe's suggestion from comments, I was able to build upon Creating Datavalidation with custom Formula to achieve both of my requirements:
var criteria = SpreadsheetApp.DataValidationCriteria.DATE_ON_OR_BEFORE;
var args = ["=TODAY()"];
var val = SpreadsheetApp.newDataValidation().withCriteria(criteria,args);
This gives me both dynamic check that uses "today()" as date, and date picker for input.