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
Solved! Go to Solution.
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
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})
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
Thank you Johannes! This is the example I was looking for. Thanks again!