Creating Status using Arcade in Dashboards

132
3
01-26-2023 10:50 AM
Labels (1)
BNix_TPA
New Contributor II

I'm trying to create a project status, but don't want to store the status in the data.  I want the status to automatically change when the date passes to be complete.  I was able to set up my map and symbolize the features based on this new status.  I now want to use the same status within my dashboard as a category picker.  How would I use this code within a dashboard?

 

var started = $feature.Startdate_time
    var closed = $feature.Enddate_time
var present = Now()

If (present >= started && present <= closed) {
    return "Active"
}
If (present <= started) {
    return "Planned"
}
else {
    return "Closed"
}
0 Kudos
3 Replies
jcarlson
MVP Honored Contributor

To get this calculated value as a category, it needs to be a real field. Not to worry, though, as a Data Expression can "bake in" the field without needing to really create it in the layer.

 

var fs = FeatureSetByPortalItem(
    Portal('your portal url'),
    'itemid of service',
    0,
    ['Startdate_time', 'Enddate_time'],
    false
)

var sql = `CASE
WHEN CURRENT_TIME() >= Startdate_time AND CURRENT_TIME() <= Enddate_time THEN 'Active'
WHEN CURRENT_TIME() <= Startdate_time THEN 'Planned'
ELSE 'Closed'
END`

return Distinct(
    fs,
    [
        {name: 'objectid', expression: 'objectid'},
        {name: 'status', expression: sql}
    ]
)
        

 

You'll need the picker to hook into the data expression, as opposed to the layer. The trouble, though, is that the way category selectors work is based on field values. So even if you got this into your picker, you won't be able to use it against the original layer.

It would still work if you used the Data Expression layer in all your other widgets, though. Just add extra fields to the Distinct function to make them available to the output. What other widgets are in your dashboard?

- Josh Carlson
Kendall County GIS
0 Kudos
BNix_TPA
New Contributor II

Thank you for your reply!  I plugged this into the data expression and this error returned:

Expected "!=", "*", "+", "-", "/", "<", "<=", "<>", "=", ">", ">=", "AND", "BETWEEN", "END", "IN", "IS", "LIKE", "NOT", "OR", or [ \t\n\r] but end of input found.

I'm not super savvy with Arcade and have taken a few trainings.  My dashboard itself is very simple, it consists of a map, list, and indicator showing active projects. I could add a pie chart to accomplish the filter you are referring to.  I was also hoping there was a way I could have the default of the map only show active projects when it is initially opened.  I know that kind of functionality exists with the category selector and that's why I was looking to go that route.  Any other ideas on how to accomplish this are greatly appreciated.

0 Kudos
jcarlson
MVP Honored Contributor

D'oh! A Case statement needs an End. I will edit the code block in the original post. Just put the word END right after 'Closed' in the SQL string.

- Josh Carlson
Kendall County GIS
0 Kudos