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.
Thanks,
Robert
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
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?)
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.
Thanks,
Robert
I tried using this script below but I cannot say for certain where I am going wrong. I tried modifying the script that you sent me earlier, but it only return two of the values. I will keep trying but if you manage to figure it out would you mind letting me know so I can work through and see where I was making mistakes.
var Edited = Date($feature.EDITDATE);
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(Now()), 'years')<=1){
var status = 'Completed';
}
else {
(DateDiff(Year(Edited), Year(Now()), 'years')>1)
var status = 'Not COmpleted';
}
return status
Thanks,
Robert
And to respond to your question about the parser I do not know. It is really confusing to debug, but hopefully Esri might find a solution for it. I can see where certain characters close and which ones do not but in either case it is a bit complicated.
One thing you need to be careful of is the units part of the DateDiff() function. It looks like you're trying a calculation inside there for your first two. It should be set up as DateDiff(datetime1, datetime2, 'units'). When this is part of an if statement, you can then use an operator (<2, eg) after the closing parenthesis. Your third and fourth DateDiff() functions look to be written correctly, though the fourth is not needed. That else case will only ever trigger if the years are greater than 1 anyway.
What happens when you delete the fourth DateDiff() function and try changing the first two to the following?
if(DateDiff(Edited, Now(), 'hours')<2){
else if(DateDiff(Today(), Edited, 'hours')<8{
[Note that you shouldn't need to specify that the hours are greater than 1, because anything under 2 will already be caught by the first statement]
var Edited = Date($feature.EDITDATE);
if(DateDiff(Edited, Now(), 'hours')<2){
var Status = 'In Progress';
}
else if(DateDiff(Today(), Edited, 'hours')<8{
var status = 'Current';
}
else if(DateDiff(Year(Edited), Year(Now()), 'years')<=1){
var status = 'Completed';
}
else {
var status = 'Not COmpleted';
}
return status
Oh ok. I was trying to set up the scenario so that anything under two hours
would be symbolized as one color but the thing that I want sure I'd is if I
wanted to stumble a statement similar to one below:
Now() < x < EditDate
I was looking to see if I could write a script so that the symbology would
change for the in between condition while preserving the other conditions.
I just don't want to write the script that ends up satisfying two arguments.
If there is a way to achieve this without creating separate conditions that
might be satisfied that either leaves a gap or overlaps because I'm not
sure if there is or not. I'm looking to satisfy one set of conditions
without overlapping or leaving a gap. Amy idea would be greatly
appreciated.
Thanks
Robert
The above expression should have no overlap or gap that I am aware of, due to the way else if statements are handled. if a feature was last edited 3 minutes ago, it would evaluate the first statement as True, and no further else case is triggered, returning a value of 'In progress'. If a feature was edited 3 hours ago, it would evaluate the first statement as False, and the second statement as True; the function then stops evaluating there, returning a value of 'Current'. A feature edited 3 weeks ago evaluates as False for the first two statements, and True for the third, returning a value of 'Completed'. A feature edited 3 years ago evaluates all three statements as False, and triggers the final Else case ('Not Completed').
Is this the workflow you're looking for?
A couple things to consider: