Hi,
I am trying to use the list widget in AGOL dashboard to create a species list for a layer I have containing species data. I want the list to only include the name of each species once and show a sum of total counts. I've done this by using a data expression using the code below, but have two issues I'm struggling to solve:
1) The species field uses a domain list, and its currently showing the code rather than the label. How do I get it to pull out the label? (I assume its somehow using 'DomainName(feature, field)'. But can't work out where to put this in the code and what the 'feature' part should be? $feature, $datapoint, my fs variable?.
2) I also would like other fields from the data to be available in the data expression to enable me to filter the list in the dashboard e.g. by location etc. But again can't work out how to include these in the script so they are pulled out but not used to group the list by.
Any help on either/both of these would be amazing,
Thank you
Hi @KatieQuantrell,
Have you tried looking into the data expressions for Dashboards. With the data expressions you can create features from other features, like the featuresetbyportalitem.
In addition to that, regarding the description vs the code, then you are correct about using the DomainName to get the actual description rather than the code for a domain.
var DayFields = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
var infoFields = []
for( var d in DayFields ){
Push( infoFields, { 'name' : DayFields[d] , 'type' : 'esriFieldTypeString' , length: 6 } )
}
var D = DateAdd( Today() , -Weekday(Today()) , 'days' )
var Values = {}
for( var i in DayFields ){
Values[ DayFields[ i ] ] = Text( D , 'MMM D' )
D = DateAdd( D , 1 , 'days' )
}
/* for multiple values in the feature modify the example below
var ListofValues = []
for( var i in ListofValues ){
Push( ListofValues, { attributes: {'A':a, 'B':b, 'C',c },geometry: {shape} } )
}
var MultipleRecords = FeatureSet(Text({
'fields': Fieldlist,
'geometryType': 'Polygon',
'features' : ListofValues
}))
*/
var DOW = FeatureSet(Text({
'fields': infoFields,
'geometryType':'',
'features' : [{'attributes': Values }]
}))
return DOW
You can also modify the code above to have the geometry of either all features or ones that only match the values. Just be mindful that if you want the geometry that pertains to all of the unique values then you will need to merge all of the geometries but if you want the unique geometries then you will need to append multiple records for the new feature.