Select to view content in your preferred language

Arcade - Dictionary with One Key and 2 Values

1918
3
Jump to solution
08-31-2021 12:11 PM
BradenWarns
Occasional Contributor

I am trying to create an attribute rule using a dictionary in Arcade for our Zoning layer. The dictionary will have one key and two values. I want to compare the values in the dictionary to two fields. However, I am not sure how to call each value in the expression.

The idea is to use value one as my control against one field. Then update another field with value two.

Ex:

Value 1 = R-1

Value 2 = Single-Family District

Field 1 = R-1

Field 2 = Single-Family and Two-Family District

Value 1 == Field 1

Value 2 != Field 2

Therfore Field 2 will be update with the Value 2.

 

Any help will be appreciated. Thanks

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Your example doesn't state what the dictionary keys would be. As it looks right now, you could just do this:

// Calculation Rule on Field 2
// Triggers: Update, Insert

// return early if Field1 is empty
if(IsEmpty($featue.Field1)) {
  return $feature.Field2  // or return null
}
// create the dictionary
var value_dict = {
  "R-1": "Single-Family District",
  "ABC": "Other stuff",
}
// return the right value for Field2
return value_dict[$feature.Field1]


// you could also do it with a list:
value_list = [
  ["R-1", "Single-Family District"],
  ["ABC", "Other stuff"],
]
for(var i in value_list) {
  if(value_list[i][0] == $feature.Field1) {
    return value_list[i][1]
  }
}
// return a default value if Field1 is not in the list
return null

Have a great day!
Johannes

View solution in original post

3 Replies
IamTrash
Emerging Contributor

You don't need a dictionary type to do this. I recently did something very similar on a zoning layer. The way I accomplished this was creating a definition query where value 2 != field 2 then I performed a calculate field on the remaining field where I used a loop like for (var i in Zoning){return i.nameoffieldyouwant})

 

0 Kudos
JohannesLindner
MVP Frequent Contributor

Your example doesn't state what the dictionary keys would be. As it looks right now, you could just do this:

// Calculation Rule on Field 2
// Triggers: Update, Insert

// return early if Field1 is empty
if(IsEmpty($featue.Field1)) {
  return $feature.Field2  // or return null
}
// create the dictionary
var value_dict = {
  "R-1": "Single-Family District",
  "ABC": "Other stuff",
}
// return the right value for Field2
return value_dict[$feature.Field1]


// you could also do it with a list:
value_list = [
  ["R-1", "Single-Family District"],
  ["ABC", "Other stuff"],
]
for(var i in value_list) {
  if(value_list[i][0] == $feature.Field1) {
    return value_list[i][1]
  }
}
// return a default value if Field1 is not in the list
return null

Have a great day!
Johannes
BradenWarns
Occasional Contributor

Thank you Johannes! This is the example I was looking for. Thanks again!

0 Kudos