Select to view content in your preferred language

Symbology: Arcade Expression for Date Range not working

2591
7
Jump to solution
01-28-2019 01:01 PM
deleted-user-jxpbpbjlZInj
Deactivated User

So I want to symbolize a polygon layer with two different symbols: one is red if it hasn't been surveyed in the last 30 days. The other is gray if it has been surveyed in the last 30 days. This is the expression I wrote, but the symbology is homogeneously red! No difference, despite differences in values in my fields:

var rightnow = now()
var lastedit = $feature.LastSurveyDate
var difference = (rightnow - lastedit)

If (difference >30) {
return "This has not been surveyed in past 30 days"
}
else {
return "This has been surveyed in past 30 days"
}

HALP!

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Please be aware that "difference" is an existing function, which might be causing the problem. Could you try with a different variable name, like "days" for example?  

var days = DateDiff(Now(), $feature.LastSurveyDate, "days");
if (days > 30) {
    return "This has not been surveyed in past 30 days";
} else {
    return "This has been surveyed in past 30 days";
}

View solution in original post

7 Replies
KenBuja
MVP Esteemed Contributor

Try this expression

var rightnow = now();
var lastedit = $feature.LastSurveyDate;
var difference = DateDiff(rightnow, lastedit, 'days');

If (difference > 30) {
  return "This has not been surveyed in past 30 days";
}
else {
  return "This has been surveyed in past 30 days";
}‍‍‍‍‍‍‍‍‍‍

That can also be simplified to

var difference = DateDiff(now(), $feature.LastSurveyDate, 'days');

If (difference > 30) {
  return "This has not been surveyed in past 30 days";
}
else {
  return "This has been surveyed in past 30 days";
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
deleted-user-jxpbpbjlZInj
Deactivated User

 Nope. Doesn't make a difference. Still a homogeneous red. 

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you share a snippet of your data?

0 Kudos
deleted-user-jxpbpbjlZInj
Deactivated User

Below there are two dates filled in for last survey date (a date field that I added after the feature service was published to AGOL as a hosted FS.) These two survey dates are attributes in two of the red grids above it. 

Here's the expression:

0 Kudos
XanderBakker
Esri Esteemed Contributor

Please be aware that "difference" is an existing function, which might be causing the problem. Could you try with a different variable name, like "days" for example?  

var days = DateDiff(Now(), $feature.LastSurveyDate, "days");
if (days > 30) {
    return "This has not been surveyed in past 30 days";
} else {
    return "This has been surveyed in past 30 days";
}
KenBuja
MVP Esteemed Contributor

Are you getting the expected result when you click "Test". Here I'm using a data set where the EditDate was in July 2018 and am just returning the days value

deleted-user-jxpbpbjlZInj
Deactivated User

I DID get the expected result when I tested. I also got the expected result when I just looked at the value that the datediff gave me. It was just when it was applied it didn't seem to actually effect the symbology. This  morning I took Xander Bakker‌'s advice and used a different var in place of "diff" and YES - this seemed to work, but only after I switched my > to a <

Then I just set the wording in the symbology to make it all look kosher. So. Yea. THANKS EVERYONE!!