Has anyone needed to get the most current record by filtering on day/time of a dynamic data set (it is currently a hosted feature service in AGO)? The data is refreshed about every 10 mins. I am trying to use filtering or Arcade expressions. Thank you. Jake Skinner
Please check queryTopFeaature API on the feature service layer and it is available on online feature service. It is the same as query API but it will return you the most recent or oldest record/feature(s).
The key to this API is to pass the topFilter param which can specify the orderBy and groupBy fields.
topFilter:
{ "groupByFields" : "your-groupby_field(s)", "orderByFields" : "sometime_field ASC", "topCount" : 1 // You can return the most recent 1 or more record}
Khaled Hassen
Online Feature Service Dev. Lead
Hi Khaled, Thanks so much for the response and I was able to get it to return the correct records. How do I use this as a layer in my web map?
Thanks!
Tonya
One way to do this is by creating a view layer from this service.
You can then set the topFilter in the view. Once this is done, then you should be able to view the results like any other filter in the layer.
To set the topFilter in the view, you will need to use the layer admin API and pass the followings:
https://servicesurl/ArcGIS/rest/admin/services/view-name/FeatureServer/1/updateDefinition
{
"viewLayerDefinition" : {
"topFilter" : {
"orderByFields" : "<yourfileldName> ASC",
"groupByFields" : "your _groupBy_fields",
"topCount" : 1
}
Hello Tonya Kauhi & Khaled Hassen
I'm struggling to form my queryTopFeatures correctly. I am attempting to query the most recent record for each FacilityID in a table using the below:
https://xyz.com/arcgis/rest/services/xyz/xyz/FeatureServer/101/queryTopFeatures?where=&objectIds=&time=&topFilter={"groupByFields": 'FacilityID', "topCount": 1, "orderByFields": 'workdate'}&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Foot&outFields=*&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnZ=false&returnM=false&resultType=&f=pjson
I'm unsure if it matters but know that 'workdate' is a date field. Please can I ask for help on how to form this query correctly?
Thanks
Hi Andrew,
I see you are passing the filter above in the url without any url encoding. This will not work.
The topFilter in the url will look like:
&topFilter=%7B"groupByFields"%3A+"Editor"%2C+"topCount"%3A+1%2C+"orderByFields"%3A+"EditDate"%7D+
Pl. note I used double quote for the group by and order by fields.
Khaled
Do I encode the whole URL or only the query portion of REST URL, as below:
https://xyz/arcgis/rest/services/xyz/xyz/FeatureServer/101/%3Fwhere%3D%26objectIds%3D%26time%3D%26topFilter%3D%7B%22groupByFields%22%3A+%E2%80%9Cassetkey%E2%80%9D%2C+%22topCount%22%3A+1%2C+%22orderByFields%22%3A+%E2%80%9Cworkdate%E2%80%9D%7D%26geometry%3D%26geometryType%3DesriGeometryEnvelope%26inSR%3D%26spatialRel%3DesriSpatialRelIntersects%26distance%3D%26units%3DesriSRUnit_Foot%26outFields%3D%2A%26returnGeometry%3Dtrue%26maxAllowableOffset%3D%26geometryPrecision%3D%26outSR%3D%26returnIdsOnly%3Dfalse%26returnCountOnly%3Dfalse%26returnExtentOnly%3Dfalse%26returnZ%3Dfalse%26returnM%3Dfalse%26resultType%3D%26f%3Dpjson%0D%0A%0D%0A
Either way, i'm not getting any results back when i drop this into my browser. What am I doing wrong here?
Khaled, Can you take a look at this related question?
https://community.esri.com/message/920629-update-hosted-layer-view-definition-w-topfilter-to-show-only-most-recent-record
Thanks.
Jay
Hi Khaled,
Is it possible to use topFilter to group by on geometry? My issue is that have a point feature class which is constantly being updated, and I want to be able display the most recently created features. At the moment, AGOL draws randomly, so it isn't possible to display the most recent.
Many thanks
Josh
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.