Select to view content in your preferred language

How to Get Symbology to Change for Editing date and Time in Webmap using custom expressions

4599
16
07-12-2018 09:50 AM
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi,

I was wondering if there is script for the arcade functions in the web map style to show the current edit date as one style and the other edited dates as another. I am looking to symbolize the difference between what is current and what isn't. Any help would be greatly appreciated. I can symbolize today and now but I want to symbolize based on the edit dates.

Thanks,

Robert

0 Kudos
16 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Ok. I wasn't sure how the expressions would work if given those conditions.

I guess it mostly has to do with my understanding of how the scripting

would work. I thought about it some more this morning and realized the

reason that I wasn't able to see anything when I changed the symbology

using the scripts; I realized it was on the feature service that we haven't

deployed yet but will hopefully get it deployed soon. I tried testing it

and I didn't see the changes that I was looking for but then I realized I

didn't leave the edits long enough to see any other changes. I'm going to

try this again with the scripts but leave it overnight or two to allow the

scripts to work. Thanks for your help. If I find something or some way that

would account for time zone changes then I'll let you know. That could be

something that could be looked into. Perhaps even something to account for

daylight savings as well.

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Thanks Nick,

I haven't considered that but I will definitely keep that in mind. I tried the set of scripts that you sent me last time and for some reason, when I tested it, I didn't quite get what I was looking for. It didn't change the symbology when it was ran but I think I might have a solution that might allow me to combine parts of the scripts that were posted and see if I can manipulate the script so that only certain symbologies will be drawn so long as the certain conditions remain true. The one you sent about the due dates I think I can reconfigure to set certain boundaries without trying to run to many if then expressions. I will let you know if it works or not. The one you posted the first time worked really well and I think I can build on it and perhaps be able to define the criteria and have it symbolized accordingly. I will post on here if I run into any troubles or if I manage to get the scripts working. Here is the script that you sent me the first time that worked when I tested it.

var Edited = Date($feature.EditDate);

if(DateDiff(Now(), Edited, 'hours')<=2){
  var Status = 'New';
}
else if(DateDiff(Today(), Edited, 'days')>=0){
  var Status = 'Old';
}
else {
  var Status = 'Current'
}

return Status

So I think this script and parts of the other scripts might be enough for me to run multiple tests and see which other set of scripts should work. I think if I try to combine too many if else-if scenarios then either too many conditions might end up being met or too little. I will let you know if I manage to get it to work. Thanks for all your help.

0 Kudos
NickDierks1
Frequent Contributor

For what it's worth, in case it helps you figure out any similar expressions, this is one that I'm using right now, and it's been working just fine in my web map:

var Due1 = Date($feature.Followup1);
var Due2 = Date($feature.Followup2);

if(IsEmpty($feature.Followup2)){
  if(DateDiff(Today(), Due1, 'days')>=0){
    var TimeColour = 'Yellow';
  }
  else {
    var TimeColour = 'Blue'
  }
}
else if(DateDiff(Today(), Due2, 'days')>=0){
  var TimeColour = 'Red';
}
else {
  var TimeColour = 'Yellow'
}

if($feature.Override != 'None'){
  var Colour = $feature.Override;
}
else if(IsEmpty($feature.Abated)){
  var Colour = TimeColour;
}
else {
  var Colour = 'Green';
}

return $feature.Category + Colour

Workflow:

A code violation is recorded, and a due date is set. If the violation is not abated in that timeframe, another warning is given and a second due date is set. A citation is issued if there's still no resolution by that date. Due dates can be adjusted as needed depending on the situation.

Need:

Newly recorded violations show up on the map as blue. After they pass the first due date, they turn yellow. After they pass the second due date, they turn red. Once abated, they turn green.

Arcade explanation:

  1. If there's no second due date set yet, then it checks if today is before or after the first due date, setting the colour to blue (normal) or yellow (past due).
  2. Otherwise, if a second due date is set, it checks if today is before or after that deadline, setting the colour to yellow (past due) or red (outstanding).
  3. These expressions set one variable, TimeColour.
  4. Then it checks if there's a status override. If there is, the colour is set to that override, ignoring the above variable.
  5. Otherwise, it checks if there's an abatement date recorded (the violation has been resolved). If not, then the symbol colour is set to the above TimeColour variable. If there is, the colour is set to green.
  6. Lastly, in addition to the colour that was calculated out, the expression returns the violation category as well. The overall result is 20 possible combinations (5 categories, each with 4 possible colours).

This can probably be simplified (I could start with the check for the override, for example), but it should give you an idea of a more elaborate setup of date-based arcade expressions, should you decide to get a little fancy.

Happy coding!

KellyGerrow
Esri Alum

Hey Nick Dierks‌ and Robert Phillips‌,

There is a ton of great help in this post. Could one of you mark the most correct answer as correct so other users know that this thread has an answer and more.

Good feedback about the parser, we'll look into making it easier to troubleshoot.

-Kelly

0 Kudos
MichailaMusman
Occasional Contributor

Hi Nick-- I'm using some of the expressions you've written above to symbolize my points by last edit date. I'm also trying to symbolize by the year each point was created, which is specified in one my fields.  So what I'm trying to do is have each year be assigned a color, i.e. 2017 = yellow, 2018 = purple, 2019 = orange, and then have all three years change to one uniform color once they are updated.  Here's what I have to change symbology by date edited.  Do you have any suggestions for achieving symbology by year as well?

var water_date = $feature.EditDate;
var days_dif = DateDiff(Now(), water_date, "days");
var result = "water status";
if (days_dif <= 14) {
 result = "Complete";
} else if (days_dif > 14) {
 result = "Needs Water";
} 
return result;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
NickDierks1
Frequent Contributor

So, if I'm reading this right, you want any "Needs water" point to be symbolized based on year, and any "Complete" point to have a single symbol, regardless of year created? If so, that should definitely be doable.

First, is the year you want to use in its own field, or part of more complete date field? If it's the latter, then be sure to use Year(datefield) to extract just the year from the rest of the date.

Next, your Line 6 in your sample doesn't need to be an else if. If you change it to just else { , your code works just the same (because the else case is always going to trigger at  >14 days).

Whether or not you change Line 6, the solution lies in changing Line 7: result = "Needs Water " + [year] (with [year] being your year field, or Year() function mentioned above)

This will give you the following results:

Complete

Needs Water 2017

Needs Water 2018

Needs Water 2019

Go ahead and assign colours in your map as you wish. Let me know if this helps, or if you're looking for something a little different.

MichailaMusman
Occasional Contributor

Worked perfectly!  Thank you so much for your help!

Michaila

0 Kudos