Select to view content in your preferred language

Return the description of a domain instead of the code for Arcade Popup

628
2
Jump to solution
08-20-2024 11:06 AM
Labels (1)
Calley
by
New Contributor

The goal of this code is to find the top 3 most planted trees in each polygon and rank them in a popup. The code below accomplishes that, but it returns the code of the domain and not the description. 

For example, I want the list to look like this "1. Maple 2. Oak 3. Hickory", but arcade returns this instead"1. AC 2.QU 3. CA". 

I have attempted to use DomainName to return the description, but I am having difficulty.  When I run the code below in an attempt to return the description, nothing is returned.  Please help me return the description and not the code for this feature class.

 

var trees = FeatureSetByName($map, "Trees - Trees")

var countspecies = Intersects(trees, $feature)

var stats = Groupby(countspecies, "commonname",[
  {name: "total" ,expression: "commonname", statistic: 'COUNT'}
  ])

var topspecies = Top(OrderBy(Filter(stats, "commonname <> ''"), "total desc"), 3)


var result = 'The top species in this tract are:'

var num = 0

for (var item in topspecies){
  num++
  var num_species = item["total"]
  var species_name = DomainName(item,FeatureSetByName($map, "Trees - Trees"), "commonname")

  result += TextFormatting.NewLine + num + ". " + " " + species_name + " " + num_species + " " + "planted"
}

return result

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

What you have to do is get the domain's codedValue array and for each item, loop through that array to get the correct domain name.

This should work

var trees = FeatureSetByName($map, "Trees - Trees");

var countspecies = Intersects(trees, $feature);

var stats = Groupby(countspecies, "commonname",[
  {name: "total" ,expression: "commonname", statistic: 'COUNT'}
  ]);

var topspecies = Top(OrderBy(Filter(stats, "commonname <> ''"), "total desc"), 3);


var result = 'The top species in this tract are:';

var num = 0;
var codedValues = Domain(trees, 'commonname').codedValues;
for (var item in topspecies){
  num++;
  var num_species = item["total"];
  var species_name;
  for (var i in codedValues){
    if (codedValues[i].code == item['commonname']) species_name = codedValues[i].name;
  }

  result += TextFormatting.NewLine + num + ". " + " " + species_name + " " + num_species + " " + "planted";
}

return result

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

What you have to do is get the domain's codedValue array and for each item, loop through that array to get the correct domain name.

This should work

var trees = FeatureSetByName($map, "Trees - Trees");

var countspecies = Intersects(trees, $feature);

var stats = Groupby(countspecies, "commonname",[
  {name: "total" ,expression: "commonname", statistic: 'COUNT'}
  ]);

var topspecies = Top(OrderBy(Filter(stats, "commonname <> ''"), "total desc"), 3);


var result = 'The top species in this tract are:';

var num = 0;
var codedValues = Domain(trees, 'commonname').codedValues;
for (var item in topspecies){
  num++;
  var num_species = item["total"];
  var species_name;
  for (var i in codedValues){
    if (codedValues[i].code == item['commonname']) species_name = codedValues[i].name;
  }

  result += TextFormatting.NewLine + num + ". " + " " + species_name + " " + num_species + " " + "planted";
}

return result

 

Calley
by
New Contributor

This is great, thank you so much for your help!!

0 Kudos