I'm a novice at Arcade and am struggling to get this to work, any help would be appreciated.
Setup:
Feature Class Hydrant_Data contains a field called Hydrant_ID and a GlobalID
Standalone Table Flushing_Records also contains a field called Hydrant_ID and Hydrant_ID_GUID
The table was connected to the FC through a relationship class called Hydrant_ID_Flushing_Records_Relationship, structured as One to Many and with the Origin Primary Key as the GlobalID and the Origin Foreign Key as the Hydrant_ID_GUID
How to do I pass the Hydrant_ID of the parent record to the child record?
What's the environment you're working in? I'm guessing since you mention the relationship is in a relationship class in a geodatabase, you could create an attribute rule in ArcGIS Pro? You could do something like this:
// get the related record
var asset_id = $feature.GlobalID
var assets = FeatureSetByName($datastore, "databasename.schema.Flushing_Records")
var asset = First(Filter(assets, "Hydrant_ID_GUID = @asset_id"))
// if there is no related record, end expression
if(asset == null) { return }
// else populate attribute with the edit. In this case, Hydrant ID from $feature is being written into Hydrant_ID of related table.
return {
edit: [{
className: "databasename.schema.Hydrant_Data",
updates: [{
objectID: asset.OBJECTID,
attributes: {
Hydrant_ID: $feature.Hydrant_ID,
}
}]
}]
}
I've gotten expressions like this to work going the opposite way (ie, write a value from a new related record into the parent feature class), but this should still work fine.
I implement this prior to seeing your response and it appears to be functionally similar. Thanks for the response!
var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature, "Hydrant_Data_Flushing_Records_Relationship"), "Hydrant_ID");
var cnt = Count(relatedrecords);
var relatedinfo = "";
if (cnt > 0) {var info = First(relatedrecords);
relatedinfo = info.Hydrant_ID;
}
return relatedinfo;
I implemented the following Arcade script:
var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature, "Hydrant_Data_Flushing_Records_Relationship"), "Hydrant_ID");
var cnt = Count(relatedrecords);
var relatedinfo = "";
if (cnt > 0) {var info = First(relatedrecords);
relatedinfo = info.Hydrant_ID;
}
return relatedinfo;
Did some quick testing and this appears to work as needed--where each hydrant can have multiple flushing records and calculation attribute rule is correctly pulling the Hydrant_ID from the parent and applying it to the child table for each record.