Hi All,
I used this script to delete all the features from a hosted feature layer where it had relationships and had sync capability enabled on it.
import arcgis
from arcgis.gis import GIS
gis = GIS("https://site.maps.arcgis.com", "username", "password")
feature_layer_item = gis.content.search("<item-id>")[0]
flayers = feature_layer_item.layers
flayer = flayers[0]
#count = flayer.query(return_count_only=true)
max_objid = flayer.query(out_statistics=[{"statisticType":"MAX","onStatisticField":"OBJECTID","outStatisticFieldName":"MAX_OBJ"}], return_geometry=False)
maxoid = max_objid.features[0].attributes['MAX_OBJ']
#Delete in steps of 20000, in case the dataset is large
i = 0
step = 20000
#replace maxoid with count if attempting to delete features based on feature count
#using for loop
#for i in range(1,20000,maxoid):
while i <= maxoid:
i += step
flayer.delete_features(where=f"OBJECTID <= {i}")
print(i)
print("Feature Layer was truncated")
Thanks,
Imtiaz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.