Display Latest Feature In a Feature Service

3821
1
05-07-2020 05:14 PM

Display Latest Feature In a Feature Service

When working with feature services, there may be duplicate features, but with different attributes.  Take for example a Survey123 form that reports the shelter's current population.  Multiple submissions for the same shelter can be provided throughout the day, but you would only like to display the most recent feature.  One way to achieve this is through the top filter parameter that's part of the Query Top Features operation.  This can be applied to an ArcGIS Online hosted feature layer view.  Below are the steps on how to do this.

1.  In ArcGIS Online, navigate to your hosted feature service Item Details and click Create View Layer:

2.  Specify a Name, Tags, and Description for the view:

In this example, you can see the Shelters have multiple entries for the same shelter, but with different Count values. 

3.  Go to the Item Details of the hosted view layer.  Scroll down and click View next to the URL:

4.  Click on the layer name under Layers

5.  Edit the URL and add admin between rest/services:

6.  Scroll down to the bottom of the page and click Update Definition

7.  Delete all the JSON in the Update Layer Definition dialog box

8.  Navigate to https://jsonlint.com/ to help define the JSON object to be passed

9.  There are 3 parameters that will be passed in the JSON object:

  • orderByFields:  the name of the field that contains the time you want to sort.  ASC = Ascending, DESC = Descending
  • groupByFields:  the name of the field to be incorporated in the grouping
  • topCount:  defines the number of features returned from the top features query and is a numeric value

 In this example, I want to show each shelter by the latest edit date, so I will enter the following (note:  enter the field names and not the field aliases):

{
	"viewLayerDefinition": {
		"topFilter": {
			"orderByFields": "last_edited_date DESC",
			"groupByFields": "sheltername",
			"topCount": 1
		}
	}
}‍‍‍‍‍‍‍‍‍

Enter this into JSONLint and validate it is correct.  Then paste this into the Update Layer Definition dialog box:

10.  Click Update Layer Definition

The hosted view layer will now show only the most recent feature for each shelter:

Comments
Nat_Carter
New Contributor

Is this applicable for Enterprise v10.9.1?  I have successfully applied the topFilter definition to the "viewLayerDefinition" but the view layer is reporting a Data Error.  The other properties in the JSON for the hosted feature view layer of "viewDefinitionQuery" and "definitionExpression" are null.  It looks like the "viewDefinitionQuery" property is what gets affected by the Set View Definition tool in the view layer's Visualization tab but the topFilter syntax can't be applied there.

Thanks for the help!  

Version history
Last update:
‎12-12-2021 03:35 AM
Updated by: