<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Filter feature layer paramter based on attributes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1564694#M73276</link>
    <description>&lt;P&gt;I don't think there's a way to do it as an in-built filter, but you use tool validation to check.&lt;/P&gt;&lt;P&gt;Try something like this? (Not super-tested but it should work)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateMessages(self, params):
    Samples = params[0]
    if Samples.value:
        field = {f.name:f.type for f in arcpy.ListFields(Samples.value)}
    valueFieldType = fields.get("value", None)
    SampDateFieldType = fields.get("SampleDate", None)
    if not (valueFieldType and SampDateFieldType):
        Samples.setErrorMessage('Feature Class must have a field named "value"'
                                'and a field named "SampleDate')
    if valueFieldType != "Single":
        Samples.setErrorMessage('"value" field must be a Float field')
    if SampDateFieldType != "Date":
        Samples.setErrorMessage('"SampleDate" field must be a Date field')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2024 15:33:00 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2024-12-04T15:33:00Z</dc:date>
    <item>
      <title>Filter feature layer paramter based on attributes</title>
      <link>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1564641#M73272</link>
      <description>&lt;P&gt;Is it possible to filter the available feature layers for a parameter based on the attribute table the same way we can filter based on the shape type:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Define the sample paramter
Samples = arcpy.Parameter(
    displayName="SamplePoints",
    name="SamplePoints",
    datatype="GPFeatureLayer",
    parameterType="Required",
    direction="Input")
# Require the sample to be Points
Samples.filter.list = ["Point"]

# Reqiore the feature class of the layer to have the Float 'value' and Date 'SampleDate'
# ???  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here i want only to be able to select a feature layer for a feature class that have the attribute "value" and "SampleData"&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 14:08:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1564641#M73272</guid>
      <dc:creator>MortenBackNielsen</dc:creator>
      <dc:date>2024-12-04T14:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Filter feature layer paramter based on attributes</title>
      <link>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1564694#M73276</link>
      <description>&lt;P&gt;I don't think there's a way to do it as an in-built filter, but you use tool validation to check.&lt;/P&gt;&lt;P&gt;Try something like this? (Not super-tested but it should work)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateMessages(self, params):
    Samples = params[0]
    if Samples.value:
        field = {f.name:f.type for f in arcpy.ListFields(Samples.value)}
    valueFieldType = fields.get("value", None)
    SampDateFieldType = fields.get("SampleDate", None)
    if not (valueFieldType and SampDateFieldType):
        Samples.setErrorMessage('Feature Class must have a field named "value"'
                                'and a field named "SampleDate')
    if valueFieldType != "Single":
        Samples.setErrorMessage('"value" field must be a Float field')
    if SampDateFieldType != "Date":
        Samples.setErrorMessage('"SampleDate" field must be a Date field')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 15:33:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1564694#M73276</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-12-04T15:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Filter feature layer paramter based on attributes</title>
      <link>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1565048#M73279</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thank you for you solution, I learn a lot from it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping for a way to filter the options in the drop down, but this works as well Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def updateMessages(self, params):
    samples = params[0]
    if samples.value:
        fields = {f.name:f.type for f in arcpy.ListFields(samples.value)}
    
        valueFieldType = fields.get("value")
        SampDateFieldType = fields.get("SampleDate")

        if valueFieldType is None or SampDateFieldType is None:
            samples.setErrorMessage('Feature Class must have a field named "value"' 'and a field named "SampleDate')

        if valueFieldType != "Double":
            samples.setErrorMessage(f'"value" field is of type {valueFieldType} must be a Float field')

        if SampDateFieldType != "Date":
            samples.setErrorMessage(f'"SampleDate" field is of type {SampDateFieldType} must be a Date field')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 10:04:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1565048#M73279</guid>
      <dc:creator>MortenBackNielsen</dc:creator>
      <dc:date>2024-12-05T10:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filter feature layer paramter based on attributes</title>
      <link>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1565108#M73280</link>
      <description>&lt;P&gt;Glad it worked. One thing to watch out for is that you check to see if the field type is "Double", but you your error message says the field type must be "Float", which is actually "Single". You should either change what you're checking for or change your error message.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 13:59:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/filter-feature-layer-paramter-based-on-attributes/m-p/1565108#M73280</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-12-05T13:59:49Z</dc:date>
    </item>
  </channel>
</rss>

