Order a List by Calculated Field and Include a Map Action

442
1
Jump to solution
09-19-2022 10:28 AM
Labels (1)
WorcesterGTSS
New Contributor III

I'm trying to create a list that

a) includes a calculated numeric field (ticket duration in days) based on two date fields in my dataset 

b) is sorted by that calculated field (i.e., the records with the largest # of days appear at the top of the list.) and

c) includes a map action that zooms to a particular record when the record is clicked on in the list.

I have successfully calculated the field but have not been able to order the list by the calculated field AND include the map action all in the same list.

In the first approach I tried, I used an existing feature layer in the dashboard map as the data source and calculated the ticket duration field in the Advanced Formatting section of the list settings using Arcade. When I do it this way, I'm also able to add the zoom map action to the list. The problem is that I can't figure out how to sort the list based on the ticket duration calculated field. Here is my code in the Advanced Formatting section:

var project_dur = DateDiff($datapoint["cl_date"], $datapoint["date"], 'days');

return {
textColor: '',
backgroundColor:'',
separatorColor:'',
selectionColor: '#99156f',
selectionTextColor: '',
attributes: {
time_len: project_dur,
}
}

In the second approach I tried, for the data source I created a data expression that references the portal item feature layer for the list and calculated my field in this expression. Because of this, I'm able to sort the list based on that field directly in the list settings. However, the zoom map action does not work when I do it this way. Here is the data expression I wrote for this approach:

var fields = ["objectid", "date", "cl_date", "category", "closed", "status", "id"]
var fs = Filter(FeatureSetByPortalItem(Portal("PORTAL URL"), "PORTAL ITEM ID", 0, fields),"closed = 'Yes' AND status <> 'Cancelled' ")

var dict = {
fields: [
{name: 'objectid', type: 'esriFieldTypeString'},
{name: 'id', type: 'esriFieldTypeInteger'},
{name: 'status', type: 'esriFieldTypeString'},
{name: 'date', type: 'esriFieldTypeDate'},
{name: 'cl_date', type: 'esriFieldTypeDate'},
{name: 'project_duration', type: 'esriFieldTypeDouble'}
],
geometryType: '',
features: []
}

var index = 0
for (var p in fs){
dict.features[index++] = {
attributes: {
objectid: p['objectid'],
id: Number(p['id']),
status: p['status'],
date: Number(p['date']),
cl_date: Number(p['cl_date']),
project_duration: DateDiff(p['cl_date'], p['date'], 'days')
}
}
}

return FeatureSet(Text(dict))

If anyone has a suggestion on how I can include the 3 criteria above in one list, it would be greatly appreciated.

Thank you,

Samara

 

0 Kudos
1 Solution

Accepted Solutions
WorcesterGTSS
New Contributor III

I ended up calculating the ticket duration field directly in my dataset rather than in the dashboard. I think that will improve performance and it also allows me to include the map action and sort the list by the ticket duration field directly in the dashboard settings without a data expression.

View solution in original post

0 Kudos
1 Reply
WorcesterGTSS
New Contributor III

I ended up calculating the ticket duration field directly in my dataset rather than in the dashboard. I think that will improve performance and it also allows me to include the map action and sort the list by the ticket duration field directly in the dashboard settings without a data expression.

0 Kudos