Attribute Rule to Update Feature Layer with Related Table Value

2684
4
09-18-2020 11:02 AM
JoeBorgione
MVP Emeritus

I have created a number of attribute rules that populate a given field from underlying feature layers (thanks to Xander Bakker‌).  Now I would like to update a feature layer attribute from a related table.  In Frequently Asked Questions | ArcGIS for Developers  the question How do I access data from related tables sends you to the Featureset page.  But I don't see anything there regarding a related table.

In a nutshell, I have a feature layer of City polygons that I would like to relate to a table of corresponding three letter city codes.  When I add a new feature (centerline, address point etc) I can update the City name easily, but how would I update that City code from a related table?  I'd like to avoid adding yet another field to the City features.  Both the feature layer and related table will reside in the same $datastore, an enterprise geodatabase.

That should just about do it....
0 Kudos
4 Replies
HusseinNasser2
Esri Contributor

Hey Joe

You can use FeatureSetByRelationshipName to read related records, and you can use DML to update features from other tables. 

This blog might help 

Advanced Attribute Rules – Editing features on another class with attribute rules 

JoeBorgione
MVP Emeritus

Thank you Hussein Nasser‌; I missed the FeatureSetByRelationshipName.  I'll check it out.

That should just about do it....
0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Also check out - arcade-expressions/UpdateParentFeature.md at master · Esri/arcade-expressions · GitHub 

I did not use FeatureSetByRelationship, but did use a PKey/FKey style lookup

JoeBorgione
MVP Emeritus

I ended up going a different route using dictionaries, so for the sake of discussion, here is what I went with:

var cityDict = {"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 townDict ={"COPPERTON" : "COP", "EMIGRATION CANYON" : "EMC",
            "KEARNS" : "KEA", "MAGNA" : "MAG", 
            "UNINCORPORATED" : "SCO", "WHITE CITY" : "WHC"}


var city = $feature.INCMUNI_L  //$feature.INCMUN_R
var town = $feature.UNINCCOM_L //$feature.UNINCCOM_L

if (HasKey(cityDict, city)){
    return cityDict[city];
} else if (HasKey(townDict, town)){
    return uninc[town]
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In my area of operations, we have both incorporated cities as well as unincorporated townships. The field  INCMUNI_L has the value of the incorporated municipality on the left side of a centerline while the field UNINCCOM_L has the unincorporated community on the left side of a centerline. I should mention that when adding a new centerline, these attributes are updated with another attribute rule that takes the required info from an underlying polygon feature.

I have two rules, one for the left side of the centerlines feature and one for the right side that update a field called CityCode_L or CItyCode_R respectively using the associated values from the dictionaries.

That should just about do it....