Select to view content in your preferred language

Flag row if any field has invalid domain values

484
1
Jump to solution
06-24-2022 05:12 AM
Bud
by
Honored Contributor

I want to create a field that would flag a row if its values don’t match its domains. 

Is there a way to populate such a field using an Arcade calculation attribute rule?

  • For each field, if the field has a domain, and if the value doesn’t match the domain, then set DOMAIN_VALUES_VALID to ‘INVALID’.
  • Hopefully, the script could be dynamic, rather than needing to hardcode a list of fields with domains in the script.

I’m aware that it’s possible to prevent invalid rows in the first place using a constraint attribute rule. That’s a valid option. But I also want to experiment with a flag too. Thanks.

 

Edit: Unfortunately, I forgot to mention that the table has subtypes (with domains).

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Point FC with coded value domain ["Value 1", "Value 2", "Value 3"] on TextField:

JohannesLindner_0-1656085219861.png

 

Using CalculateField, I can insert other values (same works with arcpy cursors and attribute rules):

JohannesLindner_1-1656085353003.png

JohannesLindner_3-1656086354261.png

 

 

Calculation Attribute Rule on that point fc, field IntegerField, triggers insert & update

 

function code_is_in_domain(domain_dict, code) {
    for(var i in domain_dict.codedValues) {
        if(domain_dict.codedValues[i].code == code) {
            return true
        }
    }
    return false
}


var attributes = Dictionary(Text($feature)).attributes  // a dictionary
for(var field in attributes) {  // loop through the dictionary keys ( = field names)
    var domain_dict = Domain($feature, field)
    if(domain_dict != null && !code_is_in_domain(domain_dict, $feature[field])) {
        return 0//"INVALID"
    }
}
return 1//"VALID"

 

 

(you could of course also populate a text field with that rule, or you could return booleans and use it as constraint rule)

 

I can still input values that are not in the domain, but now the flag gets set:

JohannesLindner_2-1656086284856.png

 


Have a great day!
Johannes

View solution in original post

1 Reply
JohannesLindner
MVP Frequent Contributor

Point FC with coded value domain ["Value 1", "Value 2", "Value 3"] on TextField:

JohannesLindner_0-1656085219861.png

 

Using CalculateField, I can insert other values (same works with arcpy cursors and attribute rules):

JohannesLindner_1-1656085353003.png

JohannesLindner_3-1656086354261.png

 

 

Calculation Attribute Rule on that point fc, field IntegerField, triggers insert & update

 

function code_is_in_domain(domain_dict, code) {
    for(var i in domain_dict.codedValues) {
        if(domain_dict.codedValues[i].code == code) {
            return true
        }
    }
    return false
}


var attributes = Dictionary(Text($feature)).attributes  // a dictionary
for(var field in attributes) {  // loop through the dictionary keys ( = field names)
    var domain_dict = Domain($feature, field)
    if(domain_dict != null && !code_is_in_domain(domain_dict, $feature[field])) {
        return 0//"INVALID"
    }
}
return 1//"VALID"

 

 

(you could of course also populate a text field with that rule, or you could return booleans and use it as constraint rule)

 

I can still input values that are not in the domain, but now the flag gets set:

JohannesLindner_2-1656086284856.png

 


Have a great day!
Johannes