Field Maps: calculated expression (arcade) to fill a field when another one has a specific value

1865
2
Jump to solution
06-19-2023 04:30 AM
MichelleMarek
New Contributor

Hey guys

 

I'm a bit new to arcade and trying to figure out how to do a simple expression in field maps to fill in a value.

I have field1 with a string and field2 with two possible values via domains. If in field1 a specific string is chosen, I want field2 to select the correct value (from the domain) automatically.

I tried it like that:

 

if ($feature.field1 == "string 1") {
  var output = DomainName($feature, "field2", 1);
  return output;
}

 

 

or without specifying that it's a domain:

 

if ($feature.field1 == "string 1") {
  var output = "string2";
  return output;
}

 

 

Im not sure if the second option is possible because there is a domain set on the field.
But nevertheless, both didn't work. 

Can someone help me? It's probably simple and I don't get something right.

1 Solution

Accepted Solutions
MichelleMarek
New Contributor

Thanks for the reply!
I figured it out with your input. It's not quite like your example but your suggestion about returning the domain code was right.

It works like that:

if (DomainName($feature, "field1") == "string1") {
  return 1
}

So I tried some things and it only works that way. The domain code has to be returned (not the string) and it seems that for the clause, you have to use the DomainName function (I selected it like that from the variable selection in the arcade editor).

But because it only works over the domains, I can't use it for an attribute with different domains depending on subtypes. The Arcade Editor doesn't seem to recognize these domain values.
But for me it kind of works when I use a different attribute.

Thanks again 🙂

View solution in original post

0 Kudos
2 Replies
LuisaC
by
Emerging Contributor

This may be something you've already finished by now, but have you tried something like this: 

if ($feature.field1 == "string 1") {

  return 1

}

It seems like maybe the domain code is what needs to be output but both of the code snips are returning the domain name instead.  

MichelleMarek
New Contributor

Thanks for the reply!
I figured it out with your input. It's not quite like your example but your suggestion about returning the domain code was right.

It works like that:

if (DomainName($feature, "field1") == "string1") {
  return 1
}

So I tried some things and it only works that way. The domain code has to be returned (not the string) and it seems that for the clause, you have to use the DomainName function (I selected it like that from the variable selection in the arcade editor).

But because it only works over the domains, I can't use it for an attribute with different domains depending on subtypes. The Arcade Editor doesn't seem to recognize these domain values.
But for me it kind of works when I use a different attribute.

Thanks again 🙂

0 Kudos