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!
Solved! Go to Solution.
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";
}
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";
}
Nope. Doesn't make a difference. Still a homogeneous red.
Can you share a snippet of your data?
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:
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";
}
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
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!!