Hello fine folks of the Geonet boards. Finally dipping my toes into advanced formatting by way of Arcade within the Dashboard, List widget > Advanced formatting. I've made some progress understanding the syntax and getting some customization proof of concept testing (successful) to change background colors based on a status field. This article was great.
var color = Decode($datapoint["status"],
'Tentative', 'lightgreen',
'In-Progress','orange',
'')
return {
textColor: '',
backgroundColor: color,
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
// attributes: {
// attribute1: '',
// attribute2: ''
// }
}
But now I'm looking for examples, advice etc. to getting to the next step, which is to color the background based on some date fields and logic. Essentially replicating the filter, I have enabled on the data options tab to display records where Date field1 is within xx days OR datefield1 is before today AND date field2 IS NULL.
-One color if Date field1 is WITHIN XX DAYS
OR
-Second color if date field1 is BEFORE NOW AND date field 2 IS NULL
A series of if statements would handle this, together with the right date functions. Try something like this?
var dt1 = $datapoint['DateField1']
var dt2 = $datapoint['DateField2']
var day_range = XX
var bgcolor = ''
if ((DateDiff(dt1, Now(), 'days') < day_range) && (dt1 > Now())){
bgcolor = 'first color'
} else if ((dt1 < Now()) && IsEmpty(dt2){
bgcolor = 'second color'
}
return {
backgroundColor: bgcolor
}
Thank you @jcarlson - this has been extremely helpful in allowing me to better understand syntax and these simple date functions. I've been able to get the first part of the statement to work, no problem.
Getting barked at when I add in the else if statement "Unexpected End of Script" and I'm not sure how to conquer this error. Any tips for troubleshooting? I'd love to become more self sufficient with these simple arcade expressions and dates. Endless use cases here...
Ah, shoot. In my else if line, I'm missing a )
} else if ((dt1 < Now()) && IsEmpty(dt2)){