HOW TO
In ArcGIS Online, when working with records collected using the ArcGIS Survey123, it is useful to display only the most recent records for reporting or decision-making purposes. By using ArcGIS Notebooks, records can be compared across the dataset based on a survey date field to identify and classify the latest entries by updating another field with custom values such as Recent or Outdated. Once updated, this field is used in Map Viewer to apply filters that display only the most recent records on the map.
This article provides the workflow to classify the most recent ArcGIS Survey123 records using ArcGIS Notebooks and filter them in Map Viewer.
from arcgis.gis import GIS
gis = GIS("home")
item = gis.content.get("<itemID>") #Replace <itemID> with the portal item ID of the hosted feature layer
layer = item.layers[<layer_index>] #Use the appropriate layer index based on the data
date_field = "<fieldName1>" #Replace <fieldName1> with the date field name
target_field = "<fieldName2>" #Replace <fieldName2> with the new field name
features = layer.query(
where="1=1",
out_fields="<fieldName1>,<fieldName2>",
return_geometry=False
).features
latest_date = None
for f in features:
val = f.attributes.get(date_field)
if val:
if latest_date is None or val > latest_date:
latest_date = val
print("Latest date:", latest_date)
updates = []
for f in features:
val = f.attributes.get(date_field)
if val == latest_date:
f.attributes[target_field] = "<Value1>" #Replace <Value1> with a value representing recent records
else:
f.attributes[target_field] = "<Value2>" #Replace <Value2> with a value representing older records
updates.append(f)
result = layer.edit_features(updates=updates)
print("Update completed")
print(result)
Below is the full working script for this example.
from arcgis.gis import GIS
gis = GIS("home")
item = gis.content.get("cc8ac240812f45bfafc757949fdcf740")
layer = item.layers[0]
date_field = "inspection_date"
target_field = "Date_Status"
features = layer.query(
where="1=1",
out_fields="inspection_date,Date_Status",
return_geometry=False
).features
latest_date = None
for f in features:
val = f.attributes.get(date_field)
if val:
if latest_date is None or val > latest_date:
latest_date = val
print("Latest date:", latest_date)
updates = []
for f in features:
val = f.attributes.get(date_field)
if val == latest_date:
f.attributes[target_field] = "Recent"
else:
f.attributes[target_field] = "Outdated"
updates.append(f)
result = layer.edit_features(updates=updates)
print("Update completed")
print(result)
Note: After pasting the code, click Run this cell and advance to execute the cell. Click Save As to save the notebook for future use if required.
This workflow must be re-run each time new Survey123 records are submitted. To automate the process, consider scheduling the notebook.

The map below displays the most recent ArcGIS Survey123 records.

Article ID: 000032410
Get help from ArcGIS experts
Start chatting now