Select to view content in your preferred language

Compare Future Date with Current Date in Arcade in ArcGIS Online

3983
19
01-08-2020 12:01 PM
joerodmey
MVP Alum

Hi,

I have a ArcGIS Online web map which has a feature layer (points) I created via Survey123. I have the feature layer symbolized based on the status (Not Complete, Complete, Follow-up/Reminder). The follow-up reminder status is the one I'm having issues with. This reminder status is set by the user via Surv123 and also has a date field associated with it. This date field contains the date that the user wants to be reminded on.

My goal is to have that particular point to display on the web map ONLY when the reminder date is hit. Today is Jan 8 and say the reminder date was set for Jan 10. Well I only want this point to show starting on Jan 10 and after that.

I was going to create the current date and time from Arcade with: Text(Now(),'MM/DD/Y hh:mm:ss')

and compare it to the reminder date via the layer filter in the web map. But this won't work as this Arcade field of current date/time doesn't show in the list of fields in the filter option in my web map.

Any solutions or better directions to take? Xander Bakker

Thanks,

Adam

19 Replies
MarkBockenhauer
Esri Regular Contributor

Adam,

An Arcade Expression like what follows.. should work.

var vstat = ''
var time1 = Date($feature.FollowupDate)
if ($feature.Status == 'Complete'){
vstat = 'Complete'
}
else if ($feature.Status == 'Not Started'&& DateDiff(Now(), time1, 'hours')<=0){
vstat = 'Future Follow Up'
}
else if ($feature.Status == 'Not Started'&& DateDiff(Now(), time1, 'hours')>=0){
vstat = 'Follow up Now'
}
else if ($feature.Status == 'Not Complete'&& DateDiff(Now(), time1, 'hours')>=0){
vstat = 'Still working on it'
}
else{
vstat = 'uknown state'
}
return vstat;

However, when I tried this in the Web MapViewer, the Symbol states would not generate?

My $feature.Status is a list (coded value) and I created a feature that met each of the desired states.

Was pretty sure this should work.. So, I tried it in ArcGIS Pro and...  it works.

I set the symbols for future work and "unknown" to transparent.  I also labeled all the points using a similar expression to "see" the future follow up features.

Using ArcGIS Pro I shared this as a webmap.  https://www.arcgis.com/home/webmap/viewer.html?webmap=ddbd64b2302347d299cd62bce48ac242 

and it also works in Collector. (did not try in Survey123.. but it should work)

If using ArcGIS Pro is an option for you... you can do it.

Mark

joerodmey
MVP Alum

Xander - I can't wait till that release

Mark - Thanks. I tried your arcade and was able to get it to work directly in the webmap. But I still cant filter based on arcade expressions in AGOL. I don't want the label or the symbol to show until the specified date. 

0 Kudos
MarkBockenhauer
Esri Regular Contributor

I labeled it, just to show that the feature is there and a symbol is not being drawn.  You don't need show the label.

What do you need to do with a filter?  I am not understanding that part.  Or are you saying that using ArcGIS Pro is not an option?

0 Kudos
SteveCole
Honored Contributor

I hope I don't confuse the situation but maybe this is an option. Recently, I wanted to use an Arcade field within the query filter for one of my webmaps but I found out that it isn't supported at this time (thread here). What I learned is that you can tweak the underlying SQL query using AGO Assistant and that's ultimately what I did.

In my case, I had a layer of deficient curb ramps but I only wanted to show locations that were scheduled to be repaired within the next 12 years. A wrinkle in my case is that the year field in the data I was given wasn't stored as a date object so I had to do some on-the-fly tweaking. Anyways, here's an example of the Query Definition that I swapped into the web map using the AGO Assistant:

(a5facilitycat = 'Curb Ramp') AND (m9upgradeyr >= EXTRACT(YEAR FROM CURRENT_DATE()) ) AND (m9upgradeyr <= EXTRACT(YEAR FROM CURRENT_DATE()) + 12 )

So, I'm just bringing this up since there might be a way to develop a more sophisticated SQL query outside of the Webmap environment.

Steve

joerodmey
MVP Alum

Mark - Now I need to show labels for only certain features. Is this possible with Arcade? I'm almost there. I was able to do this all in the webmap without bring it into Pro.

Steve - Thanks for the idea and ill keep it in mind if I can't get Arcade to work.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Joerodney ,

If the feature contains the information for the condition to decide whether to show the label or just an empty string, you can use Arcade to do this. What is the condition? 

0 Kudos
joerodmey
MVP Alum

Hi Xander Bakker

The condition to show labels would be "Status is not equal to Reminder"

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Joerodney , 

And the text of the label is based on an attribute I assume? 

0 Kudos
XanderBakker
Esri Esteemed Contributor

What you could probably do in that case is use the expression below (adapt it to your field names).

if ($feature.Status != "Reminder") {
    return $feature.LabelText;
} else {
    return "";
}

("Status" and "LabelText" should be replaced with the names of the fields in your data)

0 Kudos
joerodmey
MVP Alum

Thanks I'll test it out

0 Kudos