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;
Solved! Go to Solution.
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.
You might find setting up domains helpful. https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/create-modify-and-delete-do...
Hi Carl,
I did set up a domain for the CommonName field and that's what I'm using.
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")
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 code.
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.
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")