Select to view content in your preferred language

Does Arcade expressions with FeatureSetByRelationshipName work in a Dashboard list element?

2041
2
11-10-2021 11:15 PM
Labels (1)
beau_
by
Emerging Contributor

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 

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

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))

 

 

- Josh Carlson
Kendall County GIS
Rayn
by
Emerging Contributor

I have followed this code to get a new featureSet of 2 fields from an index layer and a related layer and it works but it does not return any actual features.  Im not sure what im doing wrong.  Im trying to create a featureSet that includes 1 field form the index layer and 1 field form the related table and then create a blank sum field and calculate that in the expression, but at this point I'm just trying to get a result with the two fields

Code and result below.  Console shows 16 features in my original data which is correct but 0 comes out for featureSet. 

 

Any help is appreciated!

var grant = FeaturesetByPortalItem(p,'c09f0e16e3ad480bbad17ae7f27c499a',1)
Console(Count(grant))

var features = []


for (var g in grant){
    var rel = FeatureSetByRelationshipName(g, "Grants_Supplements",["Project_Cost","Total_Cost_Change_Amount"], false)


    for (var r in rel){
        var feat = {
            'attributes': {
                'prjcost': g['Project_Cost'],
                'addcost': r['Total_Cost_Change_Amount']
            }
        };
        Push(features,feat);
    };
};

var fs_dict = {
    'fields': [
        {'name': 'Project_Cost', 'type': 'esriFieldTypeDouble'},
        {'name': 'Total_Cost_Change_Amount', 'type': 'esriFieldTypeDouble'},
    ],
    'geometryType': '',
    'features': features
}
Console(Count(features))
return Featureset(Text(fs_dict))
0 Kudos