Fixed
Status Update
Comments
je...@klinedrive.com <je...@klinedrive.com> #2
I'd also love to see this as a formula, in order to apply conditional formatting based on the whether the content of a cell passes the data validation rule or not. Something like ISVALID(value).
cb...@google.com <cb...@google.com> #3
I'm completely baffled: what's the point of "Data Validation" if there's no way of checking whether the data satisfies the condition? Could we all be missing something?
al...@niologic.de <al...@niologic.de> #4
@marc.art: The validation still validates within the UI itself; it's just that the results of the validation aren't available in code.
tp...@ithings.ch <tp...@ithings.ch> #5
This would be extremely helpful! Im looking to optimize my team's workflow and it is counterintuitive and wasteful on resources to reverse engineer the validation just to check if it is valid when that information is already shown in the UI! Please add .isValid()!!
[Deleted User] <[Deleted User]> #6
This is a blocking feature for implementing a compliance changelog of only valid entries.
[Deleted User] <[Deleted User]> #7
Would definitely be useful.
em...@geoambiente.com.br <em...@geoambiente.com.br> #8
Can't see why this isn't already available. I hope it is added soon!
ni...@gmail.com <ni...@gmail.com> #9
I've created a workaround for this issue that works in a very ugly -technically said- and slightly undetermined way.
My problem is that the validation is already done by the SpreadsheetApp, but only visually accessible by the user. It feels like that "you can see but cannot touch" :) It's against the whole idea of GAS.
I'd really love to have this result accessible (the feature implemented).
About the workaround:
It works based on the experience that the web browser implementation of catch() function allows to access thrown errors by the script editor JS code parts.
In case an invalid input into a cell is rejected by a validation rule then the system will display an error message that is catchable by the user written GAS. In order to make it work first the reject value has to be set on the specified cell then its vale has to be re-entered (modified) then -right after this- calling the getDataValidation() built in function allows us to catch the necessary error.
Only single cells can be tested with this method as setCellValues() ignores any data validation restriction (as of today).
Disadvantages:
- The validity won't be necessarily re-checked for this function: checking cell validity right after the value is inserted into it. Therefore the result of this function might be faulty.
- The code messes up the history as cells will be changed - in case they are valid.
I've tested it successfully on both Firefox and Chromium.
function getCellValidity(cell) {
var origValidRule = cell.getDataValidation();
if (origValidRule == null || ! (cell.getNumRows() == cell.getNumColumns() == 1)) {
return null;
}
var cell_value = cell.getValue();
if (cell_value === '') return true; // empty cell is always valid
var is_valid = true;
var cell_formula = cell.getFormula();
// Storing and checking if cell validation is set to allow invalid input with a warning or reject it
var reject_invalid = ! origValidRule.getAllowInvalid();
// If invalid value is allowed (just warning), then changing validation to reject it
// IMPORTANT: this will not throw an error!
if (! reject_invalid) {
var rejectValidRule = origValidRule.copy().setAllowInvalid(false).build();
cell.setDataValidation(rejectValidRule);
}
// Re-entering value or formula into the cell itself
var cell_formula = cell.getFormula();
if (cell_formula !== '') {
cell.setFormula(cell_formula);
} else {
cell.setValue(cell_value);
}
try {
var tempValidRule = cell.getDataValidation();
} catch(e) {
// Exception: The data that you entered in cell XY violates the data validation rules set on this cell.
// where XY is the A1 style address of the cell
is_valid = false;
}
// Restoring original rule
if (rejectValidRule != null) {
cell.setDataValidation(origValidRule.copy().setAllowInvalid(true).build());
}
return is_valid;
}
Finally let me express my gratitude for all the great works of the developers! With their shared tools/system I can solve many logistical problems of my and others' lives... Cheers!
On this issue: Hurry up guys!
My problem is that the validation is already done by the SpreadsheetApp, but only visually accessible by the user. It feels like that "you can see but cannot touch" :) It's against the whole idea of GAS.
I'd really love to have this result accessible (the feature implemented).
About the workaround:
It works based on the experience that the web browser implementation of catch() function allows to access thrown errors by the script editor JS code parts.
In case an invalid input into a cell is rejected by a validation rule then the system will display an error message that is catchable by the user written GAS. In order to make it work first the reject value has to be set on the specified cell then its vale has to be re-entered (modified) then -right after this- calling the getDataValidation() built in function allows us to catch the necessary error.
Only single cells can be tested with this method as setCellValues() ignores any data validation restriction (as of today).
Disadvantages:
- The validity won't be necessarily re-checked for this function: checking cell validity right after the value is inserted into it. Therefore the result of this function might be faulty.
- The code messes up the history as cells will be changed - in case they are valid.
I've tested it successfully on both Firefox and Chromium.
function getCellValidity(cell) {
var origValidRule = cell.getDataValidation();
if (origValidRule == null || ! (cell.getNumRows() == cell.getNumColumns() == 1)) {
return null;
}
var cell_value = cell.getValue();
if (cell_value === '') return true; // empty cell is always valid
var is_valid = true;
var cell_formula = cell.getFormula();
// Storing and checking if cell validation is set to allow invalid input with a warning or reject it
var reject_invalid = ! origValidRule.getAllowInvalid();
// If invalid value is allowed (just warning), then changing validation to reject it
// IMPORTANT: this will not throw an error!
if (! reject_invalid) {
var rejectValidRule = origValidRule.copy().setAllowInvalid(false).build();
cell.setDataValidation(rejectValidRule);
}
// Re-entering value or formula into the cell itself
var cell_formula = cell.getFormula();
if (cell_formula !== '') {
cell.setFormula(cell_formula);
} else {
cell.setValue(cell_value);
}
try {
var tempValidRule = cell.getDataValidation();
} catch(e) {
// Exception: The data that you entered in cell XY violates the data validation rules set on this cell.
// where XY is the A1 style address of the cell
is_valid = false;
}
// Restoring original rule
if (rejectValidRule != null) {
cell.setDataValidation(origValidRule.copy().setAllowInvalid(true).build());
}
return is_valid;
}
Finally let me express my gratitude for all the great works of the developers! With their shared tools/system I can solve many logistical problems of my and others' lives... Cheers!
On this issue: Hurry up guys!
ku...@gmail.com <ku...@gmail.com> #10
I'm desperate for this method to be added! Please please please do it soonest possible! Thank you!
ro...@gmail.com <ro...@gmail.com> #11
Yes please implement this. I suppose the data could be checked against the data validation rules before setting the values, but that would really slow the write process down. Not to mention how much of a pain it would be to code all the validity checks to accommodate all the different possible data validation rules.
I've been starting to use Google Sheets to serve some of our company's data storage in place of data typically stored in a SQL database, but the hard data validation rules are an essential part to maintaining data integrity in the way that's possible with a SQL database.
I've been starting to use Google Sheets to serve some of our company's data storage in place of data typically stored in a SQL database, but the hard data validation rules are an essential part to maintaining data integrity in the way that's possible with a SQL database.
pa...@leptonsoftware.com <pa...@leptonsoftware.com> #12
Please add this. It will bring down so much bad code that I have put in place due to lack of this function.
[Deleted User] <[Deleted User]> #13
Please add this in asimple manner: isValid() true or false
da...@pcg.io <da...@pcg.io> #14
I would say the methis should be intiutive to read.
Range.dataValidate() :: [][]bool
Since we are doing DataValidations ...
Range.dataValidate() :: [][]bool
Since we are doing DataValidations ...
du...@gmail.com <du...@gmail.com> #15
I need it like a thirsty desert traveler needs a few drops of water.
[Deleted User] <[Deleted User]> #16
I need it like a few drops of water need hydrogen and oxygen
bu...@grel.ist.edu.pk <bu...@grel.ist.edu.pk> #17
Must I beg?
it...@gmail.com <it...@gmail.com> #18
Seems that begging is necessary...
di...@gmail.com <di...@gmail.com> #19
Also require this, so i can track any validations fails centrally, without logging into each spreadsheet and sheet to check which is time consuming.
og...@gmail.com <og...@gmail.com> #20
OK Google... We know you can do it !
ma...@populus.ai <ma...@populus.ai> #21
Nearly 5 years later and still no change..
I don't think this will happen
I don't think this will happen
av...@gmail.com <av...@gmail.com> #22
+1
da...@gmail.com <da...@gmail.com> #23
It would be very cool
bj...@gmail.com <bj...@gmail.com> #24
+1
ma...@gmail.com <ma...@gmail.com> #25
+1
b6...@heb.com <b6...@heb.com> #26
+1
ga...@gmail.com <ga...@gmail.com> #27
+1
ja...@dcms.gov.uk <ja...@dcms.gov.uk> #28
+1
am...@digitalowl.com <am...@digitalowl.com> #29
+1
gl...@gmail.com <gl...@gmail.com> #30
+1
Description