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
NOTE: I'm just barely learning Arcade myself right now, so please take this example with a large grain of salt, but DateDiff() was something I used for symbolizing data based on dates. I think something like this ought to put you in the right direction.
var Edited = Date($feature.Edited);
if(DateDiff(Today(), Edited, 'days')>=1){ var Status = 'Old';}else { var Status = 'Current'}
return Status
Then when you symbolize according to type, all of your features should be broken down as either Old or Current.
Thanks Nick. I was able to get it to work perfectly fine. I changed the $feature.Edited to $feature.EditDate which made the arcade script work with what I was looking to do. I tested to see if it works and so far it works the way I was hoping for. So thank you very much for your help. I tried several things and I wasn't sure what I was doing wrong since I am also new to this. I realized there are more capabilities for symbology than I thought otherwise, so I thought to look into it further.
If i wanted to add a third condition such as the past hour or two in addition to the script above. How would I go about writing that. I tried a few things, one of them worked but when I tried adding a third, it didn't. Is there a way to write a script so that I can symbolize the past hour as one symbol, the current edit date as another, and then anything beyond the current edit date as another.
For that you would want to insert an else if statement. I haven't done any calculations based on time yet myself, but something like this ought to work, or at least get you close:
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<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This will check first if the time is within 2 hours. If not, it will check if the time is 1 or more days old. Lastly, if neither condition is true (which should only be the case if the days match and it's more than 2 hours old), it defaults to "Current".
(As an aside: Why is there no code parser specifically for Arcade? Or am I missing something?)
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<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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:
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!
Thanks Nick. I was trying to write an else if statement but because I don't fully understand the context of how these scripts are written, it makes it difficult to write. I thought I was writing it correctly because I wrote it as:
if(DateDiff(Edited, Now(), Hour(Now()-Edited<2))){ var Status = 'In Progress';}else { if(DateDiff(Today(), Edited, (Hour(Now())-Hour(Edited)>1<8)))} var status = 'Current';}else { if(DateDiff(Year(Edited), Year(Edited),'years')=0) var status = 'Completed' }}}return Status
I apparently was close but wasn't sure if the way I was writing it would even work. I had something written like this and it tested out correctly but then I changed something and couldn't get it back. So I will keep trying to see which script works. I am using the editor tracking date to see if we can use this kind of symbology to keep track of workers in real time. Thank you very much Nick. If do find one that works I will be sure to post it.
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
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;<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
Worked perfectly! Thank you so much for your help!
Michaila
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.