Select to view content in your preferred language

Show all attributes from related table using Arcade

1563
2
Jump to solution
11-12-2023 08:47 PM
anbinh
by
Frequent Contributor

Hi Community,

 

Having read few posts about using Arcade expression to show attributes from a related table, I get the idea to use "FeatureSetByRelationshipName" to access certain attributes values or summarise a group of attribute values, while the attribute names need to be provided anyway. 

 

However, I wonder if it possible to show all the attributes of the related records from the related table in the pop-up window? This means we do not need to know what the attribute names are, and it can dynamically include any new fields if the source related table got updated?

 

What I expect is similar as ArcGIS Pro that if a selected feature has related data, all the related data's attribute will be shown as a table in the pop-up. 

 

The environment is Portal 11.1. I have pseudo code as below where "inspections" is the related table. Basically, is there any way to modify the code that it shows all the attributes without providing the attribute names in the "inspection for...loop"?

var relationshipName = "NameOfYourRelationship"; // Replace with the actual name of your 1:M relationship

// Get the related inspections using the relationship name
var relatedInspections = FeatureSetByRelationshipName($feature, relationshipName);

// Create a table to display inspection attributes
var inspectionTable = "<table><tr><th>Inspection Date</th><th>Inspector</th><th>Other Attributes...</th></tr>";

// Loop through each related inspection
for (var inspection in relatedInspections) {
    // Extract inspection attributes (replace field names accordingly)
    var inspectionDate = inspection.attributes["InspectionDate"];
    var inspector = inspection.attributes["Inspector"];
    // Extract other attributes...

    // Add a row to the table for each inspection
    inspectionTable += "<tr><td>" + inspectionDate + "</td><td>" + inspector + "</td><td>Other Attribute Values...</td></tr>";
}

// Close the table tag
inspectionTable += "</table>";

// Return the HTML table for the pop-up content
return inspectionTable;

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can use the Schema function to return the list of fields in the related table

var relatedInspections = FeatureSetByRelationshipName($feature, relationshipName);
var theSchema = Schema(relatedInspections);
var theFields = theSchema['fields'];
var theFieldList = [];
for (var index in theFields) Push(theFieldList, theFields[index].name)

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

You can use the Schema function to return the list of fields in the related table

var relatedInspections = FeatureSetByRelationshipName($feature, relationshipName);
var theSchema = Schema(relatedInspections);
var theFields = theSchema['fields'];
var theFieldList = [];
for (var index in theFields) Push(theFieldList, theFields[index].name)
anbinh
by
Frequent Contributor

Thanks Ken,

I think this is what I am looking for!

Although I haven't tried it yet, the logic makes sense to me. Thanks for your prompt solution.

 

Regards,

Anbin

0 Kudos