Select to view content in your preferred language

Use arcade dictionary based on one field to populate values for another

542
0
10-24-2023 01:51 PM
masslc
by
New Contributor II

I have two fields in my attribute table: Incorporated City Names, and Unincorporated City Names. I am trying to create a dictionary for each columns' values, and replace them with a 3-letter city code, which I would then like to populate another column with.

First, I am curious about whether I can do this with just one dictionary or if I need two, one for each column. I have included one dictionary per column in this example. Here is what I have so far and where I am getting stuck: 

 

 

//The field I am trying to populate based off of the dictionaries
var citycode = "citycode";
//One of two fields that has the values I would like to use to populate values for the above
var incmuni = "incmuni"
//The other field I would like to use
var uninccom = "uninccom"

//Define the 3-letter city code dictionaries
var incDict = {"ALTA" : "ALT", "BRIGHTON" : "BRT", "BLUFFDALE" : "BLU", 
                "COTTONWOOD HEIGHTS" : "COT","DRAPER" : "DRA", "HERRIMAN" : "HER", 
                "HOLLADAY" : "HOL","MIDVALE" : "MID", "MILLCREEK" : "MCK", 
                "MURRAY" : "MUR","RIVERTON": "RIV", "SALT LAKE CITY" : "SLC",
                "SALT LAKE COUNTY" : "SCO", "SANDY" : "SAN", "SOUTH JORDAN" : "SJC",
                "SOUTH SALT LAKE" : "SSL", "TAYLORSVILLE" : "TAY", 
                "WEST JORDAN" : "WJC", "WEST VALLEY" : "WVC"}

var unincDict ={"COPPERTON" : "COP", "EMIGRATION CANYON" : "EMC",
               "KEARNS" : "KEA", "MAGNA" : "MAG", 
               "UNINCORPORATED" : "SCO", "WHITE CITY" : "WHC"}

 

 

This is where I have tried various things, but mostly have followed this kind of logic (sorry if my arguments are the wrong way around, I have tried them in various ways but am new to this):

 

 

//if there is a value for the incmuni field, create variable, use it to populate the citycode column with its respective 3-letter code equivalent using the incDict dictionary
//else return the 3-letter code equivalent using the uninc dictionary

if (HasKey(unincDict, uninccom)) return;
var citycodeUpdated = unincDict[citycode];
else (HasKey(incDict, incmuni)) return;
var citycodeUpdated = incDict[citycode];

 

 

 I would then like to return the values to the citycode column like this:

 

 

return {
    "result": {
        "attributes":
            Dictionary(
                citycode, citycodeUpdated)
    }
}

 

 

 Thank you for any help in advance!

0 Kudos
0 Replies