Select to view content in your preferred language

Field Parameters: Limit the fields available?

610
3
Jump to solution
10-05-2023 02:30 PM
AlfredBaldenweck
MVP Regular Contributor

Pretty simple. I have a field parameter, dependent on another parameter.

I want to keep certain fields out of drop-down for this field parameter, e.g. OBJECTID. I don't want it, can't use it for this task, I don't want to see it.

How can I accomplish this? 

 

I tried assigning a filter, but that's not supported on fields, so my current workaround is to use a multivalue string parameter and making the filter be all the fields whose names aren't ObjectID, etc. 

 

0 Kudos
2 Solutions

Accepted Solutions
DonMorrison1
Occasional Contributor III

Would something like this work?

p1.filter.list = [f.name for f in arcpy.ListFields(p0.value) if f.name not in ['OBJECTID', '<other undesireable fields>']]

View solution in original post

AlfredBaldenweck
MVP Regular Contributor

That's almost exactly what I ended up doing.

I changed the Field Parameter to a string parameter (since I only needed the names and you can only filter field types), then 

udFields.filters[0].list = [a.name for a in arcpy.ListFields(inExcel.value)
                                            if a.name.lower() not in 
                                                ["objectid", "globalid", 
                                                "guid", keyField.valueAsText.lower()]]

 I should probably add OID in there, too, I guess.

View solution in original post

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

Filters are supported for field parameters, but only for field types.

Field types can be found here: https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/field.htm

 

So for example, to only show numerical fields:

 

def getParameterInfo(self):
    p0 = arcpy.Parameter(name="layer", displayName="Layer", datatype="GPFeatureLayer")
    p1 = arcpy.Parameter(name="field", displayName="Field", datatype="Field"),
    p1.parameterDependencies = ["layer"]
    p1.filter.list = ["integer", "single", "double"]
    return [p0, p1]

 

 

This sadly doesn't help with excluding specific field names, but maybe it's enough for your use case.


Have a great day!
Johannes
DonMorrison1
Occasional Contributor III

Would something like this work?

p1.filter.list = [f.name for f in arcpy.ListFields(p0.value) if f.name not in ['OBJECTID', '<other undesireable fields>']]
AlfredBaldenweck
MVP Regular Contributor

That's almost exactly what I ended up doing.

I changed the Field Parameter to a string parameter (since I only needed the names and you can only filter field types), then 

udFields.filters[0].list = [a.name for a in arcpy.ListFields(inExcel.value)
                                            if a.name.lower() not in 
                                                ["objectid", "globalid", 
                                                "guid", keyField.valueAsText.lower()]]

 I should probably add OID in there, too, I guess.

0 Kudos