AnsweredAssumed Answered

Find Specific Field Name in MXD Layers

Question asked by mitchh300 on Sep 29, 2016
Latest reply on Oct 3, 2016 by Dan_Patterson

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

#User input as 'String' type
feederID = arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

#Set definition query to user set parameters
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) + "'"