Arcade expression, FeatureSet() parameter error

1637
2
Jump to solution
12-27-2021 10:12 AM
JGardner_Verina
New Contributor II

I am attempting to build an expression in ArcGIS dashboards that will return a few basic summary statistics. It draws from two related Survey123 features.

var fs01 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 0, ['*'], false);
var fs02 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 1, ['*'], false);

var deliveriesDict = {
						'deliveries': COUNT(fs01),
						'totalTanks': COUNT(fs02),
						'totalFuel': SUM(fs02, 'fuelFilled')
					}


return FeatureSet(Text(deliveriesDict));

This code returns the error "Invalid parameter." When I have it return only the dictionary and test it, it returns the expected result. I know I need to return a FeatureSet in order for the expression to work in Dashboards, but the FeatureSet() function doesn't like my parameter. I have also tried the following, with the same invalid parameter error:

var fs01 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 0, ['*'], false);
var fs02 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 1, ['*'], false);

var deliveriesDict = {
						'deliveries': COUNT(fs01),
						'totalTanks': COUNT(fs02),
						'totalFuel': SUM(fs02, 'fuelFilled')
					}
var textDict = TEXT(deliveriesDict);
var fs_dict = FeatureSet(textDict);
return fs_dict;

 

Can someone explain what I need to do to get the expression to return a FeatureSet?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

A featureset is composed of more than just attributes. What you're defining as your deliveriesDict makes more sense as a singular feature. The FeatureSet needs to have its geometry type and all fields defined separately from providing data to it.

Essentially, you're getting a one-feature output with the totals in it as attributes. Try:

var fs01 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 0, ['*'], false);
var fs02 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 1, ['*'], false);

var deliveriesDict = {
    fields: [
        {name: 'deliveries', type: 'esriFieldTypeInteger'},
        {name: 'totalTanks', type: 'esriFieldTypeInteger'},
        {name: 'totalFuel', type: 'esriFieldTypeInteger'} // or possibly a float if need be
    ],
    geometryType: '',
    features: [
        {attributes: {
            deliveries: Count(fs01),
            totalTanks: Count(fs02),
            totalFuel: Sum(fs02, 'fuelFilled')
            }
        }
    ]
}

return FeatureSet(Text(deliveriesDict));

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

A featureset is composed of more than just attributes. What you're defining as your deliveriesDict makes more sense as a singular feature. The FeatureSet needs to have its geometry type and all fields defined separately from providing data to it.

Essentially, you're getting a one-feature output with the totals in it as attributes. Try:

var fs01 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 0, ['*'], false);
var fs02 = FeatureSetByPortalItem(Portal('https://arcgis.com/'), 'id', 1, ['*'], false);

var deliveriesDict = {
    fields: [
        {name: 'deliveries', type: 'esriFieldTypeInteger'},
        {name: 'totalTanks', type: 'esriFieldTypeInteger'},
        {name: 'totalFuel', type: 'esriFieldTypeInteger'} // or possibly a float if need be
    ],
    geometryType: '',
    features: [
        {attributes: {
            deliveries: Count(fs01),
            totalTanks: Count(fs02),
            totalFuel: Sum(fs02, 'fuelFilled')
            }
        }
    ]
}

return FeatureSet(Text(deliveriesDict));

 

- Josh Carlson
Kendall County GIS
JGardner_Verina
New Contributor II

Thank you!

0 Kudos