I am trying to write an expression for use in the new map viewer to show work that has been done within the last month, three months, etc. The expression found here does most of what I need. However, most of my locations have not yet been visited and with this expression they are showing up as having been visited over 100 days ago and not in 'other values'. I've tried a few different ways to add phrasing to the expression that will create a new symbol for locations with null date fields, but that isn't working. This is likely due to lack of knowledge on my part as this is the first time I am trying to use Arcade. Is it possible to create symbology for locations with null date fields?
Solved! Go to Solution.
Which type is not being returned?
BTW, you can simplify your expression this way. On line 5, you don't need to check if the value is greater than 20, since that was already checked in line 3.
if(isEmpty($feature.cleandate)) {
return "Not yet surveyed";
} else if (DateDiff(Now(), Date($feature.cleandate), 'days') <= 20) {
return "Surveyed within the last 20 days";
} else if (DateDiff(Now(), Date($feature.cleandate), 'days') < 35) {
return "Surveyed between 20 to 35 days ago" ;
} else {
return "Surveyed more than 35 days ago";
}
Create an extra condition where you check for null values using the built in isEmpty function, this is used as such:
if(isEmpty($feature.<FIELDNAME>)){
// do stuff
}
else if(<CONDITION2>){
// do other stuff
}
else {
// if not the above do this
}
That explanation helped a lot and I was able to get the code to validate. However, I am having the same results and the empty features are still showing under the greater than 100 days. Here's my code:
if (DateDiff(Now(), Date($feature.cleandate), 'days') <= 30) {
return "Surveyed within the last 30 days" }
//areas which are surveyed more than 30 days but less than 100 days ago belong in the second group
else if (DateDiff(Now(), Date($feature.cleandate), 'days') > 30 &&
DateDiff(Now(), Date($feature.cleandate), 'days') < 100) {
return "Surveyed between 30 to 100 days ago" }
//areas which are surveyed 100 days ago or more belong in the third group
else if (DateDiff(Now(), Date($feature.cleandate), 'days') >= 100) {
return "Surveyed more than 100 days ago" }
else if(isEmpty($feature.cleandate)){
return "Not yet surveyed"}
Could this potentiallly be caused by trying to create the symbology off a field from a related table?
Date($feature.cleandate) might return 1-1-1970 if cleandate is null. I suspect this will be solved if you check for empty records first. I.e. move the isEmpty condition to the top
I moved the isEmpty condition to the top and that did resolve the null dates. The expression will only show 3 of the 4 symbology types though after I've reworked the code to be sure I have data that falls in all categories:
if(isEmpty($feature.cleandate)){
return "Not yet surveyed"}
else if (DateDiff(Now(), Date($feature.cleandate), 'days') <= 20) {
return "Surveyed within the last 20 days" }
//areas which are surveyed more than 30 days but less than 100 days ago belong in the second group
else if (DateDiff(Now(), Date($feature.cleandate), 'days') > 20 &&
DateDiff(Now(), Date($feature.cleandate), 'days') < 35) {
return "Surveyed between 20 to 35 days ago" }
//areas which are surveyed 100 days ago or more belong in the third group
else if (DateDiff(Now(), Date($feature.cleandate), 'days') >= 35) {
return "Surveyed more than 35 days ago" }
Which type is not being returned?
BTW, you can simplify your expression this way. On line 5, you don't need to check if the value is greater than 20, since that was already checked in line 3.
if(isEmpty($feature.cleandate)) {
return "Not yet surveyed";
} else if (DateDiff(Now(), Date($feature.cleandate), 'days') <= 20) {
return "Surveyed within the last 20 days";
} else if (DateDiff(Now(), Date($feature.cleandate), 'days') < 35) {
return "Surveyed between 20 to 35 days ago" ;
} else {
return "Surveyed more than 35 days ago";
}
Ken,
That simplified code actually cleared up the problem. Now it's showing all 4 categories. Thank you!
Ashley