Create validation rules for duplicate values in characteristics across all assets
Can I loop over and utilize the attributes of multiple selected assets within a single validation process?
When choosing multiple assets , is it feasible to apply a validation rule that examines various characteristics across these assets?
For instance, we want to ensure that every asset within a community possesses a distinct URI.
would be something like this:
rule {
// Define a list of URIs from attributes (assuming ‘PhSp URI’ is an attribute)
def uriList = attributes[‘PhSp URI’]
// Iterate through the list and compare each value with the others
for (int i = 0; i < uriList.size(); i++) {
def uriToCheck = uriList[i]
println(“Checking URI: $uriToCheck”)
// Use findAll to find all occurrences of the URI in the list except for the current one
def matchingURIs = uriList.findAll { it == uriToCheck }
// Check if there is more than one occurrence of the URI (excluding the current one)
if (matchingURIs.size() > 1) {
println("The URI $uriToCheck is not unique in the list.")
} else {
println("The URI $uriToCheck is unique in the list.")
}
}
}
stijnhebbrecht
Posted 2 years ago · Edited 1 year ago
0 comments