Help calculating field from coded domain

04-06-2022 01:49 PM
Labels (2)
New Contributor

I'm trying to calculate a field in the same record of an attribute table based on the code associated with a coded domain. 

I have a field ("activity") that uses a domain that contains a code (ex: 314) and description (ex: invasive removal). I select the value from the domain drop down that contains both the code and the description (ex: 314-invasive removal) combined when creating a record to match symbology to a style later. I'd like to populate a field ("ActivityCode") in the same record with only the code from the domain so it just prints "314". Then, similarly, another field that just prints the description.

The codes vary in length so using right, left, mid functions won't work unless I can use a string in calculate field to count left from the dash between the code and description?

Or is there a way to calculate the code from what is associated with what I selected?

0 Kudos
2 Replies
Esri Notable Contributor

One way I can think of is do a Select by Attribute on the coded value domain field like Code = '314-invasive removal'.  Then assuming you've got two new fields added to your feature class (ActivityCode' and 'ActivityDescription', do a Field Calculation on the selected features for the numeric value (314) and a second field calculation for the text value ('invasive removal').  Granted it's more manual than automatic but would work.  There is a Domain to Table GP tool that exports your domain to a fGDB table that you might be able to use (somehow) for field calcs.  Good luck!

0 Kudos
MVP Regular Contributor
  • create the fields "ActivityCode" and "ActivityDescription" in your table
  • use the expressions below to calculate the fields (use Arcade as language)
// Arcade expressions to calculate ActivityCode and ActivityDescription
// from Activity

// for Code
return Split($feature.Activity, "-")[0]
// for Description
return Split($feature.Activity, "-")[-1]
  • if you want this to be one automatically for new or updated features, create an Attribute Rule on your table, use the expression below.
// Calculation Attribute Rule on your feature class
// field: empy
// triggers: insert, update
var activity_split = Split($feature.Activity, "-")
return {
    "result": {
        "attributes": {
            "AcivityCode": activity_split[0],
            "AcivityDescription": activity_split[-1],

Have a great day!