Validation Rule - Checking size of attribute
I would like to check if an attribute entered by a user matches exactly a specific number of characters within a validation Rule.
How can I check this? I tried following validation rule to no luck:
rule{
given {
reference = attributes.‘ISO Alpha 2 Code’.size()
}
when {
isNotEqual(reference,2)
}
then{
condition{isNotEmpty(attributes.‘ISO Alpha 2 Code’, message: “ISO Alpha 2 Code must have exactly 2 characters”)}
}
}
jurgentock
Posted 5 years ago · Edited 1 year ago·Last reply 5 years ago
4 comments
arthurburkhardt
·5 years ago · Editedwhen {}is a filter condition (e.g. the validation rule only applies if the asset matches this condition)attributesis a map of array. When you doattributes.‘ISO Alpha 2 Code’.size(), it will tell you how many attributes of this type are related to the asset. In this case, I expect that the answer will mostly be 0 or 1 (even if the attribute has 2 characters)For your example, here’s a working code:
.find()will get the first attribute iso alpha 2, and store it as the variablecodecode &&ensures that the attribute is not null and not 0 lengthisLengthEqthen checks the length of the attribute, and will throw the error message if not 2.jurgentock
OP5 years ago · EditedGlenn,
Many thanks for your suggestion! I will give that a try
Jurgen
noor
·5 years ago · Editedhttps://datacitizens.collibra.com/forum/t/validation-scripts-method-cannot-be-found-error/830/2
Please take a look at the above URL.
glennde_groot
·5 years ago · EditedHi Jurgen,
You can make use of: isLengthEq (value, length). See for reference: String functions (collibra.com)
Regards,
Glenn