HOW TO
In Portal for ArcGIS, the Enable Attachments option can be set in a hosted feature layer to allow attaching images or files to individual features, such as attaching images to point features representing road incidents or survey locations. However, for larger datasets, it is time-consuming to manually verify if each feature contains an attachment.
The Python script provided in this article can be used to find the Object IDs of features without attachments in a Portal for ArcGIS item. In this example, the Layer_2_polygon hosted feature layer contains two features without attachments.
from arcgis import GIS
gis = GIS('<portal_URL>','<username>','<password>',verify_cert=False)
svc = gis.content.get('<portal_itemID>')
lyr = svc.layers[0] no_attach = [] oids = lyr.query(where='1=1', return_ids_only=True)['objectIds'] for n in range(len(oids)): oid = oids[n] attach = lyr.attachments.get_list(oid) if len(attach) == 0 : no_attach.append(oid)
Note: To return Object IDs of features with attachments, replace "len(attach) == 0" with "len(attach) > 0".
print(no_attach)
The code block below demonstrates the full script.
from arcgis import GIS gis = GIS('https://machines.esri.com/portal', 'Username1', 'Password1', verify_cert=False) svc = gis.content.get('Layer_2_Polygon_itemID') lyr = svc.layers[0] no_attach = [] oids = lyr.query(where='1=1', return_ids_only=True)['objectIds'] for n in range(len(oids)): oid = oids[n] attach = lyr.attachments.get_list(oid) if len(attach) == 0 : no_attach.append(oid) print(no_attach)
The Object IDs of features without attachments are returned after running the script.
Get help from ArcGIS experts
Download the Esri Support App