Select to view content in your preferred language

Calculated fields in ArcGIS Pro

1096
6
Jump to solution
10-27-2023 08:43 AM
AleemMohammed
Emerging Contributor
Hi Everyone,
 
I am new to using ArcGIS Pro and Arcade, I wanted to have a few calculated fields in my table, not sure what's going wrong.  I wanted the user to choose a value for the CommonName field and the app would fill out the ScientificName field. So I tried using the Arcade syntax, this was what I came up with:
 
 

 

var commonName = $feature.CommonName;
var scientificName = "";

if (commonName == "Yellow Floating Heart") {
    scientificName = "Nymphoides peltate";
} else if (commonName == "Japanese Knotweed") {
    scientificName = "Reynoutria japonica";
} else if (commonName == "Invasive Phragmites") {
    scientificName = "Phragmites australis";
} else if (commonName == "Himalayan knotweed") {
    scientificName = "Koenigia polystachya";
} else if (commonName == "Giant knotweed") {
    scientificName = "Reynoutria sachalinensis";
} else if (commonName == "Fanwort") {
    scientificName = "Cabomba caroliniana";
} else if (commonName == "European frogbit") {
    scientificName = "Hydrocharis morsus-ranae";
} else if (commonName == "Dog-Strangling Vine") {
    scientificName = "Vincetoxicum rossicum";
} else if (commonName == "Bohemian knotweed") {
    scientificName = "Reynoutria ×bohemica";
} else if (commonName == "Black dog-strangling vine") {
    scientificName = "Vincetoxicum nigrum";
    return scientificName;
} else {
    // Default value if no match is found
    scientificName = "What";
}

return scientificName;

 

I know the script is reading the correct value for the CommonName because if I set the scientifiName to CommonName the value is filled in the field. However, my script is returning "What", do you know where I might have gone wrong with this?
 
Regards,
AleemScreenshot 2023-10-27 095738.png
0 Kudos
1 Solution

Accepted Solutions
AleemMohammed
Emerging Contributor

Thanks all for helping with this, I took another look at it and figured this code was way too simple to be giving this much trouble and I made a guess that the only other complication to this was that I was using a Domain. I was using the description of the code in the domain and that was the issue 😩. Once I switched "Yellow_Floating_Heart" for "Yellow Floating Heart" in the script: 

if (commonName == "Yellow_Floating_Heart") {
    scientificName = "Nymphoides peltate";

it worked as expected. I slipped up on that. Thanks everyone for helping with this.Screenshot 2023-10-29 123513.png

View solution in original post

0 Kudos
6 Replies
CarlMorrison
Frequent Contributor
0 Kudos
AleemMohammed
Emerging Contributor

Hi Carl, 

I did set up a domain for the CommonName field and that's what I'm using.

0 Kudos
KenBuja
MVP Esteemed Contributor

Is it possible there's an extra space in the Common Name field ("Yellow Floating Heart ")? Is there any change if you modify the first line?

var commonName = Trim($feature.CommonName);

 You could also use the When function to simplify your code (also using an Implicit return)

var commonName = Trim($feature.CommonName);

When (commonName == "Yellow Floating Heart", "Nymphoides peltate",
      commonName == "Japanese Knotweed", "Reynoutria japonica",
      commonName == "Invasive Phragmites", "Phragmites australis",
      commonName == "Himalayan knotweed", "Koenigia polystachya",
      commonName == "Giant knotweed", "Reynoutria sachalinensis",
      commonName == "Fanwort", "Cabomba caroliniana",
      commonName == "European frogbit", "Hydrocharis morsus-ranae",
      commonName == "Dog-Strangling Vine", "Vincetoxicum rossicum",
      commonName == "Bohemian knotweed", "Reynoutria ×bohemica",
      commonName == "Black dog-strangling vine", "Vincetoxicum nigrum",
      "What")

 

0 Kudos
AleemMohammed
Emerging Contributor

I don't believe so, I'm using a domain for the data entry on CommonName and I copied and pasted the names from the domain table to the codScreenshot 2023-10-28 101225.pnge.

0 Kudos
AleemMohammed
Emerging Contributor

Thanks all for helping with this, I took another look at it and figured this code was way too simple to be giving this much trouble and I made a guess that the only other complication to this was that I was using a Domain. I was using the description of the code in the domain and that was the issue 😩. Once I switched "Yellow_Floating_Heart" for "Yellow Floating Heart" in the script: 

if (commonName == "Yellow_Floating_Heart") {
    scientificName = "Nymphoides peltate";

it worked as expected. I slipped up on that. Thanks everyone for helping with this.Screenshot 2023-10-29 123513.png

0 Kudos
KenBuja
MVP Esteemed Contributor

What you also could have done is used the DomainName function to get the descriptive name.

var commonName = DomainName($feature, "CommonName");

When (commonName == "Yellow Floating Heart", "Nymphoides peltate",
      commonName == "Japanese Knotweed", "Reynoutria japonica",
      commonName == "Invasive Phragmites", "Phragmites australis",
      commonName == "Himalayan knotweed", "Koenigia polystachya",
      commonName == "Giant knotweed", "Reynoutria sachalinensis",
      commonName == "Fanwort", "Cabomba caroliniana",
      commonName == "European frogbit", "Hydrocharis morsus-ranae",
      commonName == "Dog-Strangling Vine", "Vincetoxicum rossicum",
      commonName == "Bohemian knotweed", "Reynoutria ×bohemica",
      commonName == "Black dog-strangling vine", "Vincetoxicum nigrum",
      "What")

 

0 Kudos