How to search for field name in feature services using python in pro

333
1
08-25-2023 12:48 PM
JeffTimm
Occasional Contributor
for m in aprx.listMaps():
    for lyr in m.listLayers():
        if lyr.isFeatureLayer:
            arcpy.management.SelectLayerByAttribute(lyr,"NEW_SELECTION", "facilityid = 'AR022'") 
        else:
            print("  " + lyr.name + "no features")

The above code works if all the layers in the map have "facilityid" as a field.  How can I put a precheck on that constraint so this just doesn't error out.  

I thought this would work but it gives me a 999999 runtime error.

for m in aprx.listMaps():
    for lyr in m.listLayers():
        if arcpy.ListFields(lyr, 'facilityid'):
             print (lyr.name)
        else:
             print ("Field does not exist " + lyr.name)

 

any suggestions would be appreciated.

1 Reply
JeffTimm
Occasional Contributor

The above syntax works with Feature Classes from a gdb but we are trying to make this work with Feature Services as layers in a pro project map.

 

0 Kudos