Hi!
I have published a feature service and a web map to ArcGIS Online that shows some point features. Every feature has a date attribute that I would like to use for filtering. The filter is easy to set for a certain date but is it possible to set the filters value for current date? So that the filters value would be dynamic.
If this is not currently possible, it is a feature that should be implemented.
Any way that I can get around this problem? The point is that I have a lot of data in one feature service but I would like to see only those that are dated for current date.
Any luck with this? I'm trying to do something similar with a feature service. I want to filter on current date. The feature service is editable and syncable so it can be used in Collector. As you noted you can't filter on current date in the web map layer properties. I've tried setting a definition query in ArcMap when I publish the service as James Crandall suggested. The service observes the definition query when it is published but it seems that it is ignored as the current date changes or any edits are made. Did you find a work around? Did a definition query in ArcMap work for you?
Post here just in case anyone who may need it:
You can see the JSON data of your web map, and you can change the layer definition and save back.
In the layer definition, define your own expression and save.
"layerDefinition": {
.....
"definitionExpression": "CreationDate >=DATEADD(day,-1,convert(date,GETDATE()))"
......
}
USING THIS TOOL AT YOUR OWN RISK, AS IT COULD CORRUPT YOUR CONTENT. so I strongly suggest make a copy before you change anything.
Hi Simo,
I'm not familiar with JSON. Where exactly do you put this Definition Expression? Could you provide an example?
Where would I insert that expression in the following JSON:
{
"layers": [
{
"0": {
"id": 0,
"layerDefinition": {
"drawingInfo": {
"renderer": {
"type": "simple",
"label": "",
"description": "",
"symbol": {
"angle": 0,
"xoffset": 0,
"yoffset": 12,
"type": "esriPMS",
"url": "737ec596-f3ab-4-b8f4-9c952cc048d6",
"imageData": "iVBORw0KGgoAAAANSUhEUgAAACYAAAAzCAYAAAD7JnqGAAAetc",
"contentType": "image/png",
"width": 27.999999999999996,
"height": 38
}
}
}
}
},
Also, to take this idea of using arcgis online assistant one step further is there a way to query a date range to get a similar result?
Thanks for the help.
Hi Andre,
something like the following will do the trick.
JSON is javascript, and the value for layerDefinition is a Javascript object.
To answer your last question, I am pretty sure you can query a date range. all you need to do is find out the MS SQL Server syntax for it. Something like "Date >= '2015/12/01' and Date <= '2015/12/08'" should work
{
"layers": [
{
"0": {
"id": 0,
"layerDefinition": {
"definitionExpression": "CreationDate >=DATEADD(day,-1,convert(date,GETDATE()))"
"drawingInfo": {
"renderer": {
}
}
}
}
},
Having trouble getting this to work with POrtal for ArcGIS.
My layer is from a hosted service via the ArcGIS Data Store.
The following does not seem to work on a datetime field called received.
Any ideas?
"definitionExpression": "received >=DATEADD(day,-1,convert(date,GETDATE()))"
Have used this approach in the past fine on ArcGIS Online.
EDIT::
Realised the ArcGIS Data Store has postgresql under the hood, so tried this:
"definitionExpression": "received >= NOW()-'1 day'::INTERVAL"
But still no luck.
Has anyone found a better way of doing this yet?
I tried the editing the JSON in ArcGIS Online Assistant using the script that simo xu however this was not successful.
I've just found this!!
You can filter dates using In the last.