Hello Community,
I am trying to determine why this arcade expression runs during testing, but then when I click "done" and go back to the "Select a layer" page to select the expression to use in a bar chart the data expression text is grayed out with an alert saying "Unable to execute Arcade script".
I've included my script below for reference, I would appreciate any assistance or explanation why this isn;t working as intended.
Solved! Go to Solution.
I couldn't figure out a way to do that in the GroupBy statement alone, so give this a try where it creates new count fields for the two fields. I simplified it a bit so it wasn't writing all the attributes to the new FeatureSet, so see how it works.
// sets portal url
var cobportal = Portal('https://bloomingtonin.maps.arcgis.com/');
// assign Crash Dataset variables
var crashDatasetID = '50b2634c8c9443f58cd004f1138ef7ea';var crashLayerID = 0;
// assign FeatureSet variables
var crashFs = FeatureSetByPortalItem(cobportal, crashDatasetID, crashLayerID, ['number_dead', 'gis_incapacitating', 'collision_date'], true);
var fieldList = [];
Push(fieldList, {"alias":"Collision Year","editable":true,"length":4,"name":"collision_year","nullable":true,"type":"esriFieldTypeInteger"})
Push(fieldList, {"alias":"Fatal Total","editable":true,"length":4,"name":"fatal","nullable":true,"type":"esriFieldTypeInteger"})
Push(fieldList, {"alias":"Injury Total","editable":true,"length":4,"name":"injured","nullable":true,"type":"esriFieldTypeInteger"})
var temp_dict = {
fields: fieldList,
geometryType: '',
features: []
}
for (var f in crashFs) {
var attrs = {}
attrs['fatal'] = iif(f.number_dead == 'Yes', 1, 0);
attrs['injured'] = iif(f.gis_incapacitating == 'Yes', 1, 0);
attrs['collision_year'] = Year(f['collision_date'])
Push(
temp_dict['features'],
{attributes: attrs}
)
}
var newFS = FeatureSet(temp_dict);
var summaryFS = GroupBy(newFS, 'collision_year',
[
{name: 'Total Deaths', expression: 'fatal', statistic: 'SUM' },
{name: 'Total Injuries', expression: 'injured', statistic: 'SUM' } ]);
return summaryFS;
Produces this output:
Number of deaths should not be zero
I'm definitely not reading things closely enough! Just the injury field is Yes/No, so replace line 23 with
attrs['fatal'] = f.number_dead;
Ken, you have been an amazing help, I really appreciate it.