Is it possible to have symbology change color in ArcGIS Online based on feature date updated?

1948
8
Jump to solution
11-15-2017 11:24 AM
JessicaKirby2
New Contributor II

I need to have a hosted feature change color based on the date that it was last updated.  Ex: green for today, yellow for within the last 3 days and red for older then 3 days.  Is this possible?  I cannot think of a way outside of scripting python to pull the data down, process a text field,  and republish.  I am looking for a more "realtime" solution that does not require downloading the hosted service.  I do not have server so cannot publish a geoprocessing script.  I am thinking there has to be a way to use time aware data to do this?? any help out there?

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Can you try this:

var edit_date = Date($feature.EditDate);

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 = "Groomed today";
    } else if (days_dif < 3) {
        result = "Groomed Recently (Within Last 3 Days)";
    } else if (days_dif < 7) {
        result = "Groomed (Within Last Week)";
    } else {
        result = "Not Groomed";
    }
}

return result;

View solution in original post

8 Replies
by Anonymous User
Not applicable

I have not attempted to use the new programming language called "Arcade", but I had seen this at the User Conference this summer and it looks like this could potentially help you? I am not a hundred percent sure, but it could be a way. Again, I have not used this, but they were completing some similar tasks during one of the demos.

Configure pop-ups—ArcGIS Online Help | ArcGIS 

KellyGerrow
Esri Frequent Contributor

Check out this blog for more details about visualizing time with Arcade:

Visualizing Time with Arcade | ArcGIS Blog 

-Kelly

JessicaKirby2
New Contributor II

Hi Kelly,

Thanks for leading me to the blog

I see the example:

var t = Hour($feature.Created_Date); When(   t >= 22 || t < 6, "Night",   t >= 6 && t < 11, "Morning",   t >= 11 && t < 13, "Midday",    t >= 13 && t < 17, "Afternoon",   t >= 17 && t < 22, "Evening","Invalid date" );

 I've been trying to get a way to change your script to work for what I need.  Below is my attempt, but I am getting an "Invalid date" result for all results.  

var d = Date($feature.EditDate); When(    d == Today(), "Groomed Today",
   d >= Today() && d <= Today()+3, "Groomed Recently (Within Last 3 Days)",
   d >= Today()+4 &&  d < Today()+7, "Groomed (Within Last Week)",
   d >= Today()+7, "Not Groomed",
"Invalid date" );

What am I doing wrong? Any help is appreciated!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Can you try this:

var edit_date = Date($feature.EditDate);

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 = "Groomed today";
    } else if (days_dif < 3) {
        result = "Groomed Recently (Within Last 3 Days)";
    } else if (days_dif < 7) {
        result = "Groomed (Within Last Week)";
    } else {
        result = "Not Groomed";
    }
}

return result;
JessicaKirby2
New Contributor II

Thanks, with one small typo correction, changing line 1 from 

var edit_date = Date($feature.EditDate);

to 

var edit_datetime  = Date($feature.EditDate);

this worked like a charm!! Thanks so much!

XanderBakker
Esri Esteemed Contributor

Good catch! Sorry for the typo, but glad you could make it work.

0 Kudos
JessicaKirby2
New Contributor II

Xander

I am still have trouble with this script.  I cannot get all the types to work. Almost all of the classes are working accept the "Groomed Recently (Within Last 3 Days)"

I have stopped using the default $feature.EditDate for testing and added a manual date ($feature.GroomedDate)  so that I can manipulate the date to see the results...otherwise every time you edit the feature it returns "groomed today"

If you take today's date, the following should be the result:

if $feature.GroomedDate is...

12/15/17 ="Groomed today"

12/14/17 -12/13/17 ="Groomed Recently (Within Last 3 Days)"

12/12/17-12/09/17 ="Groomed (Within Last Week)"

12/08/17 or less (or no date) ="Not Groomed"

any help is greatly appreciated!!

0 Kudos
XanderBakker
Esri Esteemed Contributor

I just did a test and everything was working correctly. If there is a possibility to share access to the hosted feature layer, I could have a look what is going on. This is what I did:

In stead of pointing to an attribute, I defined the date manually (note that months are value from 0 to 11):

To verify the result I used some console statements that report back the values that you can see when you click on Messages:

The results I got are (today):

Last 3 days:

and

Last week:

and finally more time:

0 Kudos