I am using a Python script (see below) in ArcGIS Pro to update two existing hosted feature layers on ArcGIS Online. The script deletes all records in the existing hosted feature layers and appends the records from feature layers stored in an enterprise geodatabase instance. Everything works fine, and the layers are updated with no issues.
However, after updating the data in the hosted feature services this way the Modified date for the layers in ArcGIS Online does not change. Editing nearly anything about the layers or their details on AGOL does change the Modified date, so I am unsure why deleting all records and appending new ones doesn't count as a modification. These layers are accessed as reference data for field crews using Field Maps, and it would be nice for them to be able to see the last time these layers were updated.
Incidentally, I am updating these layers using a script because the Sharing > Overwrite Web Layer function is disabled when Sync and Download are enabled. Unfortunately, that's not something I can change, as crews need to cache offline copies of map areas that can be used in Field Maps.
Is there a way to change the Modified date of a hosted feature layer directly using ArcPy? If not, is there a way to change elements of the details for the layer such as the Summary or Description that shows up on the item page in AGOL? This would also cause the Modified date to change.
Here is the code I am using:
import arcpy, os, time
from arcgis.gis import GIS
import arcgis.features
# Overwrite Output
arcpy.env.overwriteOutput = True
gis=GIS("pro")
print("\n\nActive Portal in ArcGIS Pro")
startTime = time.time()
featureService = True
hostedTable = False
layerIndex = 0
########################
########################
#Update sites layer
sites = gis.content.search(query='owner:my_owner_name AND title:ArchaeologicalSite', item_type='Feature Service', max_items=1000)
print(sites)
fsItemID = "55d309530b764c289d696eded1ae0a98"
# Get featureService/hostedTable layer
serviceLayer = gis.content.get(fsItemID)
if featureService == True:
fLyr = serviceLayer.layers[layerIndex]
elif hostedTable == True:
fLyr = serviceLayer.tables[layerIndex]
flc = arcgis.features.FeatureLayerCollection(serviceLayer.url, gis)
# Delete features in batches of 2000. OBJECTIDs will not reset
# Get Min OBJECTID
minOID = fLyr.query(out_statistics=[{"statisticType": "MIN", "onStatisticField": "OBJECTID", "outStatisticFieldName": "MINOID"}])
minOBJECTID = minOID.features[0].attributes['MINOID']
# Get Max OBJECTID
maxOID = fLyr.query(out_statistics=[{"statisticType": "MAX", "onStatisticField": "OBJECTID", "outStatisticFieldName": "MAXOID"}])
maxOBJECTID = maxOID.features[0].attributes['MAXOID']
# If more than 2,000 features, delete in 2000 increments
print("Deleting features")
if (maxOBJECTID - minOBJECTID) > 2000:
x = minOBJECTID
y = x + 1999
while x < maxOBJECTID:
query = f"OBJECTID >= {x} AND OBJECTID <= {y}"
fLyr.delete_features(where=query)
x += 2000
y += 2000
# Else if less than 2,000 features, delete all
else:
print("Deleting features")
fLyr.delete_features(where="1=1")
# Append features from featureService class/hostedTable
print("Appending features")
arcpy.management.Append(r"'layer_with_new_data'", r"hosted_feature_layer", "NO_TEST", [field mapping parameters])
########################
########################
#update surveys layer
surveys = gis.content.search(query='owner:my_owner_name AND title:CulturalResourceSurvey', item_type='Feature Service', max_items=1000)
print(surveys)
fsItemID = "ef26c44ceb0549acaae598b59fb58ffc"
# Get featureService/hostedTable layer
serviceLayer = gis.content.get(fsItemID)
if featureService == True:
fLyr = serviceLayer.layers[layerIndex]
elif hostedTable == True:
fLyr = serviceLayer.tables[layerIndex]
flc = arcgis.features.FeatureLayerCollection(serviceLayer.url, gis)
# Delete features in batches of 2000. OBJECTIDs will not reset
# Get Min OBJECTID
minOID = fLyr.query(out_statistics=[{"statisticType": "MIN", "onStatisticField": "OBJECTID", "outStatisticFieldName": "MINOID"}])
minOBJECTID = minOID.features[0].attributes['MINOID']
# Get Max OBJECTID
maxOID = fLyr.query(out_statistics=[{"statisticType": "MAX", "onStatisticField": "OBJECTID", "outStatisticFieldName": "MAXOID"}])
maxOBJECTID = maxOID.features[0].attributes['MAXOID']
# If more than 2,000 features, delete in 2000 increments
print("Deleting features")
if (maxOBJECTID - minOBJECTID) > 2000:
x = minOBJECTID
y = x + 1999
while x < maxOBJECTID:
query = f"OBJECTID >= {x} AND OBJECTID <= {y}"
fLyr.delete_features(where=query)
x += 2000
y += 2000
# Else if less than 2,000 features, delete all
else:
print("Deleting features")
fLyr.delete_features(where="1=1")
# Append features from featureService class/hostedTable
print("Appending features")
arcpy.management.Append(r"'layer_with_new_data'", r"hosted_feature_layer", "NO_TEST", [field mapping parameters])
########################
########################
#print time elapsed
endTime = time.time()
elapsedTime = round((endTime - startTime) / 60, 2)
print("Script finished in {0} minutes".format(elapsedTime))