I have a list based on a feature service and I would like to display attributes from a related table in the list.
I have successfully pulled related records in the popup of a web map, but the same Arcade expression configured in the list of a Dashboard doesn't. In fact, just leaving the the code:
var related_data = FeatureSetByRelationshipName($feature, "name_of_relationship");
displays "Unable to parse script". Check your syntax." below the expression box, but no error icon (red square with a cross) at the beginning of the line.
The question is, has anyone ever been able to configure the list of an Operations Dashbard using FeatureSetByRelationshipName Arcade expression?
Thank you.
Whenever an Arcade expression uses
In this particular setting, using the Advanced Formatting function in a List widget, you can only write your script to interact within a single feature's attributes, similar to the symbology Arcade profile. You can't even reference other features in the same layer, let alone features in other tables altogether.
If you'd like to bring related records into your list, you can certainly do so using a Data Expression, which might look like this:
// get main feature layer
var portal = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(
portal,
'itemid',
0, // or whatever the layer index is
['the', 'fields', 'you', 'want']Portal('https://www.arcgis.com')
);
// create empty features array
var features = [];
// iterate over featureset
for(var f in fs){
// grab related records for feature
var rel = FeatureSetByRelationshipName(f, 'relationship-name', ['some', 'fields'], false)
// this section will look different depending on what you want to do with the related records. for this example, i'm creating a separate record for every related record
// iterate over related records
for(var r in rel){
// create feature dict
var feat = {
'attributes': {
'first-field': f['some-field'],
'second-field: rel['some-related_field'],
'third-field: rel['another-related-field']
}
};
// push to array
Push(features, feat);
};
};
// create featureset dict, supply features array
var fs_dict = {
'fields': [
{'name': 'first-field', 'type': 'esriFieldTypeString'}, // or whatever type you need
{'name': 'second-field', 'type': 'esriFieldTypeInteger'},
{'name': 'third-field', 'type': 'esriFieldTypeDouble'}
],
'geometryType': '',
'features': features
};
return FeatureSet(Text(fs_dict))