Problem with "If, Else" in Arcade expression

1410
1
02-08-2019 11:04 AM
PeterKing
Occasional Contributor

Im sure that this is a basic question so thanks in advance. I currently have an Arcade expression within a Javascript API WebApp that determines if a feature meets a DateDiff expression. The results from the Arcade expression are then sent to a UniqueValueRenderer within the app.

var currentExpired = "IIf(DateDiff(Date(),$feature.DATERECEIVED,'days') > 365, 'Expired', 'Current')"

I am trying to add a third condition and have written the following (though not truly in Arcade):

var currentExpired = (DateDiff(Date(),$feature.DATERECEIVED,'days'))
if (currentExpired > '365') {
return 'Expired';
} else if (currentExpired < '7') {
return 'Upcoming';
} else {
return 'Current';
}
 

I am trying to symbolize features that have a DATERECEIVED greater than 365 as 'Expired', those that are less than 7 days as upcoming, and everything else as current. Unfortunately, the logic seems to be flawed in that the upcoming features being symbolized are those that have been received within the last 7 days. Where have I gone wrong?

Also, any ideas on how to write the expression in a truly Arcade format? 

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

You've put the number in quotes, meaning they're being evaluated as strings. Try this

var currentExpired = (DateDiff(Date(),$feature.DATERECEIVED,'days'))
if (currentExpired > 365) {
  return 'Expired';
} else if (currentExpired < 7) {
  return 'Upcoming';
} else {
  return 'Current';
}‍‍‍‍‍‍‍‍