Arcade custom expression in AGOL

1305
3
Jump to solution
02-20-2019 10:23 AM
LeeButler
New Contributor III

Hi all,

I'm trying to use Arcade for this first time on a hosted feature layer in AGOL.

The data for this layer is collected by a field crew using Collector for ArcGIS.  The last_edit_date field is automatically populated for each feature during data collection.

In AGOL i want to display any features where the last edit date has exceeded a year from the current date to show that an inspection is now due on that feature.

As I've said, I'm new to Arcade but tried this expression but it doesn't seem to work correctly:

var inspDate = $feature["last_edited_date"];

if (DateAdd(inspDate, 1, year) < Today()) {
    return 'Inspection overdue';
}
else {
    return 'OK';
}

Any pointers on where I am going wrong or even if it is possible to do what I am trying to do?

Thanks

Tags (2)
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

When using any of the Date functions, the units must be in quotes. Otherwise, it's interpreted as a variable. Try this

var inspDate = $feature["last_edited_date"];
 if (DateAdd(inspDate, 1, "year") < Today()) {
    return 'Inspection overdue';
}
else {
    return 'OK';
}
‍‍‍‍‍‍‍‍

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

When using any of the Date functions, the units must be in quotes. Otherwise, it's interpreted as a variable. Try this

var inspDate = $feature["last_edited_date"];
 if (DateAdd(inspDate, 1, "year") < Today()) {
    return 'Inspection overdue';
}
else {
    return 'OK';
}
‍‍‍‍‍‍‍‍
AriLukas
Occasional Contributor

I realize this is an old post but i was trying to do something similar to this but I was trying to symbolize layers differently for records that were created a week or more ago; using creatdt field created from applying editor tracking. I attempted to modify above script and inserted "week" where "year" is but it is still symbolizing features that were created today. Am i missing something or is this script not meant for what i'm trying to do. 

0 Kudos
LeeButler
New Contributor III

Thank you Ken.  This was exactly what the issue was!

0 Kudos