I am trying to find a specific field name in layers in a current working MXD, but I'm having problems getting it right. The overall goal is to loop through layers in an MXD and set a definition query based on a user input (string type). The script runs without any errors, but no definition query is set.
Could it be because the type returned by the arcpy.Describe().fields function is Unicode?
Any help or advice is greatly appreciated!
import arcpy
feederID = arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
fields = arcpy.Describe(lyr).fields
for f in fields:
if f.Name == "FEEDERID":
lyr.definitionQuery = """FEEDERID = """ + "'" + str(feederID) + "'"
arcpy.RefreshActiveView()