Users have the need to apply a dynamic date filter to a feature layer within their web map . For example, they may need to show all features that were edited on the current day. Instead of having to manually update the filter in the web map each day, the below steps will walk you through how to display features dynamically using a custom style Arcade expression.
Steps:
1. Within your web map, click the Change Style icon:
2. For the option Choose an attribute to show select Custom (Expression):
3. Add in the following Arcade expression:
var time = -1
var units = 'days' //milliseconds, seconds, minutes, hours, days, months, years
var dateField = "last_edited_date"
var pastDate = DateAdd(Date(), time, units)
if($feature[dateField] > pastDate){
return 'Open'
}
Change the first three variables to whatever values you would like. The supported units are milliseconds, seconds, minutes, hours, days, months, years. The dateField variable is the date field (i.e. last_edited_date) you will query. The above example is filtering all features that have been edited after yesterday. You can also specify anything you would like for the return. This will show for the symbology's legend:
4. Finally set a Refresh Interval so that the features will update dynamically: