Select to view content in your preferred language

Help with Arcade (date)

253
5
11-07-2024 08:28 AM
Laura
by MVP Regular Contributor
MVP Regular Contributor

Still very new to Arcade and trying to copy from a script I saw on the community.

I get an error when using this: Expression must return a number value. Any help is appreciated! I am testing this out with the last edit date Esri field but will eventually be adding in another field that calculates the date of an inspection. 

var edit_datetime = Date($feature.last_edited_date);

var result = "No information available";
if (IsEmpty(edit_datetime)) {
result = "Invalid date";
} else {
var now_datetime = Now();
var days_dif = DateDiff(now_datetime, edit_datetime, "days");
var today_date = Today();
var edit_date = Date(Year(edit_datetime), Month(edit_datetime), Day(edit_datetime));
if (today_date == edit_date) {
result = "Inspected today";
} else if (days_dif < 31) {
result = "Inspected Recently (Within Last Month)";
} else if (days_dif < 90) {
result = "Inspected (Within Last 3 Months)";
} else {
result = "Not Inspected";
}
}

return result;

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

The script works if I put in another date field or just a date. Are you using this to calculate a field? If so, I'm guessing field is numeric while your script is returning text.

0 Kudos
Laura
by MVP Regular Contributor
MVP Regular Contributor

Not calculating another field. I switched to map viewer classic and the error went away. Wonder if there is a bug of some sort in map viewer. I am on 11.2

0 Kudos
ChristopherCounsell
MVP Regular Contributor

Are you using the output to drive symbology?

I've seen this error trying to use two fields for symbology. One needs to be numeric. might need to use a single expression, instead of combining with a field.

0 Kudos
Laura
by MVP Regular Contributor
MVP Regular Contributor

Yes I am. All based off of a date field. 

0 Kudos
ChristopherCounsell
MVP Regular Contributor

If you have one field or expression on the layer using non-numeric values, you can't add a second field or expression using non-numeric values. The second variable must be numeric.

As the arcade expression seems fine and you're seeing an error in line with the above it could be this limitation you are seeing.

Try joining the two values into a single expression, or returning numeric values in this expression.

If you only want the single arcade expression driving symbology, can you share some screenshots on how you are applying it? Could be a minor workflow thing where you're adding a second variable instead of replacing the exisiting, or something specific to your version of Enterprise.

0 Kudos