Select to view content in your preferred language

Populate a value from one table to another using a joining field

712
5
Jump to solution
05-03-2022 06:40 AM
GdB_Admin
Occasional Contributor

Hello,

I am trying to populate a field based on where a joining ID is between two tables. I have a relationship class set up between two tables but I want to bring over another value than just a GlobalID. So I was trying to use an attribute class to do this but it is not working for me. Can someone help?

My joining field is LocationGlobalID = GlobalID

The field I want populated from one table to the other is GdBOrderNumber = GdBOrderNumber 

var f_gid = $feature.LocationGlobalID;

var Project = FeatureSetByName($datastore, "Database.DBO.[Other Table]", ["*"], true);
var Join = Filter(Project, "GlobalID = @f_gid");

return {
'result': $feature.GdBOrderNumber,
'edit': [
{"GdBOrderNumber": $feature.GdBOrderNumber
}
]
};

 

Thank you for your time on this. Please let me know if you have any questions
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Ah OK, in that case, you're editing the $feature itself, which makes it a little easier:

// calculation attribute rule
// triggers: insert(, update)
// field: GdBOrderNumber

var f_gid = $feature.LocationGlobalID;
var related_records = FeatureSetByName($datastore, "Database.DBO.[FeatureClass]", ["*"], false);
var Join = Filter(related_records, "GlobalID = @f_gid");

// return GdBOrderNumber of the first feature in Join
// if Join is empty (no related features found), return null
var firstJoin = First(Join)
if(firstJoin == null) {
    return null
}
return firstJoin.GdBOrderNumber

// or, if you leave the field parameter empty:
return {
    "result": {"attributes": {"GdBOrderNumber": firstJoin.GdBOrderNumber}}
}

Have a great day!
Johannes

View solution in original post

5 Replies
JohannesLindner
MVP Frequent Contributor

So, you have Table A with this rule and you want to populate the field "GdBOrderNumber" on Table B, is that correct?

 

// calculation attribute rule
// triggers: insert(, update)
// field: empty

// get the related record(s)
// either use FeatureSetByName() and Filter() like you did
// or use the relationship class:
var related_records = FeatureSetByRelationshipName($feature, "RelationShipName", ["GlobalID"], false)
// we're only interested in the related records' GlobalID, because we need that to identify them in the return dictionary

// create and fill the update array
var updates = []
for(var record in related_records) {
    // updates is an array of dictionaries
    // the dictionaries are built like this:
    // {"globalID": "GID of the edited feature", "attributes": {"Field": value}}
    var update = {"globalID": record.GlobalID, "attributes": {"GdBOrderNumber": $feature.GdBOrderNumber}}
    Push(updates, update)
}

// apply the edits
return {
    "edit": [
        {
            "className": "Database.DBO.OtherTable",
            "updates": updates
        }
    ]
}

 

To learn more about the return dictionary keywords, read this: Attribute rule dictionary keywords—ArcGIS Pro | Documentation


Have a great day!
Johannes
0 Kudos
GdB_Admin
Occasional Contributor

That is what i was looking for and thank you for the link that will help a lot

Thank you for your time on this. Please let me know if you have any questions
0 Kudos
GdB_Admin
Occasional Contributor

@JohannesLindner I spoke a bit too early on this. what you gave  me works but it is in the wrong direction form what I am looking for. the set up is the FeatureClass has the relationship class on it. When an inspection is done it is being put into the table using that GlobalID = LocationGlobalID. From here now that the Table has a new record in it I need to use that Relationship Class ID (LocationGlobalID) and grab the GdBOrderNumber field from the FeatureClass and apply it to the Table. I am putting the Attribute Rule on the Table because that is where the Insert is taking place. I tried to change the code you gave me but it keeps giving me errors or just does nothing. I tried to use the LocationGlobalID field in the dictionary like you said but it is telling me I need to use the GlobalID field, but when I do that it does not do anything. Here is what I have:

var f_gid = $feature.LocationGlobalID;
var related_records = FeatureSetByName($datastore, "Database.DBO.[FeatureClass]", ["*"], false);
var Join = Filter(related_records, "GlobalID = @f_gid");

// create and fill the update array
var updates = []
for(var record in Join) {
// updates is an array of dictionaries
// the dictionaries are built like this:
// {"globalID": "GID of the edited feature", "attributes": {"Field": value}}
var update = {"LocationGlobalID": record.GlobalID, "attributes": {"GdBOrderNumber": record.GdBOrderNumber}}
Push(updates, update)
}

// apply the edits
return {
"edit": [
{
"className": "Database.DBO.[Table]",
"updates": updates
}
]

 

Thank you for your time on this. Please let me know if you have any questions
0 Kudos
JohannesLindner
MVP Frequent Contributor

Ah OK, in that case, you're editing the $feature itself, which makes it a little easier:

// calculation attribute rule
// triggers: insert(, update)
// field: GdBOrderNumber

var f_gid = $feature.LocationGlobalID;
var related_records = FeatureSetByName($datastore, "Database.DBO.[FeatureClass]", ["*"], false);
var Join = Filter(related_records, "GlobalID = @f_gid");

// return GdBOrderNumber of the first feature in Join
// if Join is empty (no related features found), return null
var firstJoin = First(Join)
if(firstJoin == null) {
    return null
}
return firstJoin.GdBOrderNumber

// or, if you leave the field parameter empty:
return {
    "result": {"attributes": {"GdBOrderNumber": firstJoin.GdBOrderNumber}}
}

Have a great day!
Johannes
GdB_Admin
Occasional Contributor

@JohannesLindner that is what i was looking for thank you for your help

Thank you for your time on this. Please let me know if you have any questions
0 Kudos