I have an expression that I use in ArcGIS Pro to symbolize features based on the amount of days away from their expiration dates.
However, when I try to use this same expression in ArcGIS Online I get a message that says "Error There Was An Error". What's causing the error?
Hard to say, the expression looks fine to me. Why does the expiration date have to be wrapped in the Date function, though? Is the field not actually a DateTime type? Could be there's a value in that field that the Date function doesn't like, and it's throwing an error in AGOL.
I have noticed that Pro validates an expression based on a subset of features, not the whole layer. So Pro might say the expression is okay, but it hasn't actually validated it against whatever that bad value is.
Maybe try switching to bracket notation, see if that makes a difference?
$feature['EXPIRATION_DATE']
It is a datetime field. Oddly enough, removing the date function and using bracket notation still returns the same error. It appears to work when I hit Run above the expression, but then returns the error when I hit Done to save the expression.
Review the entire field. Any bad values in there?
Maybe try nesting the entire expression in another conditional check:
if (IsNull($feature.EXPIRATION_DATE)) {
return 'No Date Value'
} else if (DateDiff(Date($feature.EXPIRATION_DATE), Now(), 'days') <= 90) {
return 'Expiration Soon / Expired'
} else {
return 'Active'
}