Select to view content in your preferred language

Trying to return domain values of several fields in expression

174
4
01-14-2025 12:32 PM
Labels (1)
LandonHarris
Emerging Contributor
This is the expression that I have (written with the help of Microsoft Copilot).
All of these fields have domains but this returns null
// Define the fields you want to get the domain values for
var fields = ["util_point_type_ngas", "util_point_type_power", "util_point_type_water", "util_point_type_sswr", "util_point_type_strm", "util_point_type_telco"];

// Initialize an empty dictionary to store the domain values
var domainValues = {};

// Loop through each field and get its domain values
for (var i = 0; i < Count(fields); i++) {
    var field = fields[i];
    var mydomain = Domain($feature, field);
    
    // Check if the field has a domain
    if (!IsEmpty(mydomain)) {
        var values = [];
        for (var j = 0; j < Count(mydomain.codedValues); j++) {
            values[j] = mydomain.codedValues[j].name;
        }
        domainValues[field] = values;
    } else {
        domainValues[field] = "No domain";
    }
}

// Return the dictionary of domain values
return domainValues;
0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

This code works with my data

var fields = ["util_point_type_ngas", "util_point_type_power", "util_point_type_water", "util_point_type_sswr", "util_point_type_strm", "util_point_type_telco"];

var domainValues = {};

for (var i in fields) {
  var myDomain = Domain($feature, fields[i]);
  //console(myDomain)
  if (!IsEmpty(myDomain)) {
    var value = [];
    var counter = 0;
    for (var j in myDomain.codedValues) {
      value[counter] = myDomain.codedValues[j].name;
      counter++;
    }
    domainValues[fields[i]] = value;
  } else {
    domainValues[fields[i]] = "No Domain";
  }
}
return domainValues;
0 Kudos
LandonHarris
Emerging Contributor

The code executes fine but I get "No Domain" returned for all of the fields. I can confirm that all 6 fields do have coded domains. What am I missing here?

My ultimate goal is to return the domain values so that I can assign different styles for each coded value.

0 Kudos
gis_KIWI4
Frequent Contributor

@LandonHarris - Like Ken said the code works but could you explain how you want use different fields to symbolize. 

I don't believe the symbology profile supports arcade that returns a dictionary of arrays. 
gis_KIWI4_0-1736915191998.png

 

This might be a silly question but could you do with something like this? 

Concatenate([DomainName($feature, "util_point_type_ngas"),DomainName($feature, "util_point_type_power"), DomainName($feature, "util_point_type_water")]," | ")

 

gis_KIWI4_1-1736915541090.png

 

0 Kudos
LandonHarris
Emerging Contributor

I decided to solve the problem in the most simple way. I simplified what I was trying to do. I collected all of the coded values into 1 single field and now it works just fine.