Select to view content in your preferred language

Calculate the Asset ID Field in a related table based on the Asset Id value in the related feature class

475
4
Jump to solution
03-11-2025 12:20 PM
Labels (2)
MichaelHuffman
New Contributor

I'm trying to create an arcade expression that will populate the AssetID field in a related table named "Outfall Inspection Form" with the value in the assetid field from the related feature class, which is called "Major_Minor_Outfalls"

The table is related to the feature class via GlobalID(primary) to ParentID(foreign)

0 Kudos
1 Solution

Accepted Solutions
MichaelHuffman
New Contributor

Thank you all for the feedback. I was able to get the expression to work with the following arcade script.

// Get the ParentID from the Outfall Inspection Form (Foreign Key referencing Major_Minor_Outfalls_Hutchinson)

var parentID = $feature.ParentID;  // Ensure this matches exactly with your related table field

 

// Access the related feature class (Major_Minor_Outfalls_Hutchinson)

var relatedFeatures = FeatureSetByRelationshipName($feature,"Major_Minor_Outfalls_Hutchinson", ["assetid", "GlobalID"], true);

 

// Find the related feature where GlobalID in the feature class matches ParentID in the related table

var relatedFeature = First(Filter(relatedFeatures, "GlobalID = '" + parentID + "'"));

 

// Return the assetid if a match is found

if (!IsEmpty(relatedFeature)) {

    return relatedFeature.assetid;

}

 

return null;

View solution in original post

0 Kudos
4 Replies
Laura
by MVP Regular Contributor
MVP Regular Contributor

I use this expression for the cemetery management solution. The 'gravesite' layer is related to the 'burial' table.

var gravesiteID = FeatureSetByRelationshipName($feature,"Gravesites", ['gravesiteid'])
var feature =First(gravesiteID)
If (!IsEmpty(feature)) {
return feature ['gravesiteid']
} else {
return null
}
 
This adds the ID to the table.
DavidSolari
MVP Regular Contributor

To add on to this, if you need to pull one related record to update another, you can try something like this example to update another record.

JustinMcIntyre2
Emerging Contributor

I'm working on a similar project and found a video that helped me accomplish this titled 'Pulling Related Records with Arcade" by Esri.  It is based off code from another forum:

var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature, "RelData"), "DateModified DES");
var cnt = Count(relatedrecords);

var relatedinfo = "";
if (cnt > 0) {
    var info = First(relatedrecords);
    relatedinfo = info.ProjectPhase + " (" + Text(ToLocal(info.DateModified), "MM/DD/Y") + ")";
}

return relatedinfo;‍‍‍‍‍‍‍‍‍‍

 

However, it required slight modification. As this script pertains to pulling the first date in the associated related table. 

From what you explained, I would try this expression. In the map, go to pop up to configure the pop up, add the attribute expression and then use that expression in your text box. 

 

// Retrieve related records for the current feature
// Replace "<ADD_YOUR_RELATIONSHIP_CLASS>" with the actual relationship class name

var relatedrecords = FeatureSetByRelationshipName($feature, "<ADD_YOUR_RELATIONSHIP_CLASS>");

// Count the number of related records
var cnt = Count(relatedrecords);

// Initialize AssetID variable
var assetID = "";

// Check if related records exist
if (cnt > 0) {
// Get the first related record (assuming there's only one relevant match per feature)
var info = First(relatedrecords);

// Retrieve the ASSETID field from the related feature class "Major_Minor_Outfalls"
// Ensure "ASSETID" is the correct field name for AssetID in "Major_Minor_Outfalls"
assetID = DefaultValue($feature.ASSETID, "Unknown");
}

return assetID;

 

You will just need to find out the name of your relationship between the Table and the related table and the Feature class.  And the rest should work. If needed i can provide a few working examples of how i set mine up. 

 

Also here is the link to the video if you want it explained step by step: 

Pulling Related Records with Arcade


I hope this helped you move forward

 
MichaelHuffman
New Contributor

Thank you all for the feedback. I was able to get the expression to work with the following arcade script.

// Get the ParentID from the Outfall Inspection Form (Foreign Key referencing Major_Minor_Outfalls_Hutchinson)

var parentID = $feature.ParentID;  // Ensure this matches exactly with your related table field

 

// Access the related feature class (Major_Minor_Outfalls_Hutchinson)

var relatedFeatures = FeatureSetByRelationshipName($feature,"Major_Minor_Outfalls_Hutchinson", ["assetid", "GlobalID"], true);

 

// Find the related feature where GlobalID in the feature class matches ParentID in the related table

var relatedFeature = First(Filter(relatedFeatures, "GlobalID = '" + parentID + "'"));

 

// Return the assetid if a match is found

if (!IsEmpty(relatedFeature)) {

    return relatedFeature.assetid;

}

 

return null;

0 Kudos