<?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: Python Toolbox: hasBeenValidated vs altered in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-hasbeenvalidated-vs-altered/m-p/1536412#M72798</link>
    <description>&lt;P&gt;TLDR: &lt;STRONG&gt;altered&lt;/STRONG&gt; checks for None, &lt;STRONG&gt;hasBeenValidated&lt;/STRONG&gt; checks for errors, and both are decided during updateParameters()&lt;/P&gt;&lt;P&gt;Long explanation below:&lt;/P&gt;&lt;P&gt;Ok, here's how I understand it.&lt;/P&gt;&lt;P&gt;I have a tool with 3 parameters: param0, param1, param2.&lt;/P&gt;&lt;P&gt;param0 is going to act as a switch for the filter in param0: if it's "Y", give me one list, if it's "N" give me another list, and then I'm being lazy so I'm not going to set behaviour for anything else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;param1 is just a pick-one list, and param2 is just there for me to add a message to it.&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;LI-CODE lang="python"&gt;    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
                                displayName="Param0",
                                name="param0",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")
        # param0.value = "N"
        
        param1 = arcpy.Parameter(
                                displayName="Param1",
                                name="param1",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")        
        param2 = arcpy.Parameter(
                                displayName="Param2",
                                name="param2",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")      
        
        params = [param0, param1, param2]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        param0 = parameters[0]
        param1 = parameters[1]
        param2 = parameters[2]
        
        if param0.value == "Y":
            param1.filter.list = ["apple", "pear"]
        elif param0.value == "N":
            param1.filter.list = ["strawberry", "pineapple"]
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        param0 = parameters[0]
        param1 = parameters[1]
        param2 = parameters[2]
        
        if param0.altered:
            param0.setWarningMessage("param0 is altered")
        else:
            param0.setWarningMessage("param0 is not altered")
        
        if param1.hasBeenValidated:
            param2.setWarningMessage("param1 is validated, yeah")
        else:
            param2.setWarningMessage("param1 is not validated yet")
        
        
        return&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;What I've found by experimenting this morning is that I could only really get something useable for&amp;nbsp;&lt;STRONG&gt;altered&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;hasBeenValidated&lt;/STRONG&gt; in updateMessages(), so that's what this example is going to use.&lt;/P&gt;&lt;P&gt;I'm not sure if that's always true, but it does stand to reason that hasBeenValidated is only helpful after updateParameters(), since that's when validation happens.&lt;/P&gt;&lt;P&gt;It goes: getParameterInfo()--&amp;gt;updateParameters()--&amp;gt;updateMessages(), in that order. updateParameters() gets called when you make any chance, and updateMessages() is called immediately after.&lt;/P&gt;&lt;P&gt;In any case, here's what I think the difference is.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;altered:&lt;/STRONG&gt; Is the parameter's current value different from &lt;STRONG&gt;None&lt;/STRONG&gt;? This includes setting the default value, which is kind of dumb but whatever.&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 getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
                                displayName="Param0",
                                name="param0",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")
        # param0.value = "N" # Set the default, if you want.
        params =[param0]
        return params

    def updateMessages(self, parameters):
        param0 = parameters[0]
        if param0.altered:
            param0.setWarningMessage("param0 is altered")
        else:
            param0.setWarningMessage("param0 is not altered")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1725888773534.gif" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114577iD83E23C6BAACECF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="AlfredBaldenweck_0-1725888773534.gif" alt="AlfredBaldenweck_0-1725888773534.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I've set the default:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_1-1725888805751.gif" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114578i8DA434B11E2CDA8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="AlfredBaldenweck_1-1725888805751.gif" alt="AlfredBaldenweck_1-1725888805751.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;hasBeenValidated&lt;/STRONG&gt;: Is there are error on the parameter?&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 updateParameters(self, parameters):
        param0 = parameters[0]
       
        if param0.value == "Y":
            param1.filter.list = ["apple", "pear"]
        elif param0.value == "N":
            param1.filter.list = ["strawberry", "pineapple"]
        return

    def updateMessages(self, parameters):
        param1 = parameters[1]
        param2 = parameters[2]
        
        if param1.hasBeenValidated:
            param2.setWarningMessage("param1 is validated, yeah")
        else:
            param2.setWarningMessage("param1 is not validated yet")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_2-1725889015417.gif" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114579i2B66C56A3F25B004/image-size/large?v=v2&amp;amp;px=999" role="button" title="AlfredBaldenweck_2-1725889015417.gif" alt="AlfredBaldenweck_2-1725889015417.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Sep 2024 13:47:15 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2024-09-09T13:47:15Z</dc:date>
    <item>
      <title>Python Toolbox: hasBeenValidated vs altered</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-hasbeenvalidated-vs-altered/m-p/1536050#M72793</link>
      <description>&lt;P&gt;Third excruciating attempt to understand the sparsely document difference between&amp;nbsp;&lt;STRONG&gt;hasBeenValidated&amp;nbsp;&lt;/STRONG&gt;and&amp;nbsp;&lt;STRONG&gt;altered&lt;/STRONG&gt; when creating a Python Toolbox in Pro.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/python-toolbox-use-cases-altered-hasbeenvalidated/m-p/1327127#M72906" target="_self"&gt;my second post&lt;/A&gt;&amp;nbsp; &amp;nbsp;&lt;A href="https://community.esri.com/t5/python-questions/constructing-the-toolvalidator-class-to-validate/m-p/1314684#M68322" target="_self"&gt;my first post&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me understand:&lt;/P&gt;&lt;P&gt;1) Use cases of the two&lt;/P&gt;&lt;P&gt;2) WHEN does validation occur and WHEN does checking altered status occur?&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the oft referenced, and seemingly sole, Official ESRI documentation page on the topic,&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/customizing-tool-behavior-in-a-python-toolbox.htm" target="_self"&gt;Customizing Tool Behavior&lt;/A&gt;&amp;nbsp;,I understand the intent of&amp;nbsp;&lt;STRONG&gt;altered.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I do NOT understand WHEN is the &lt;STRONG&gt;updateParameters&lt;/STRONG&gt; method called, other than the&amp;nbsp;&lt;STRONG&gt;altered&lt;/STRONG&gt;&amp;nbsp;property is immediately updated after changing a parameter value BUT internal validation does not occur.&lt;/P&gt;&lt;P&gt;I'm utterly confused.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2024 19:00:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-hasbeenvalidated-vs-altered/m-p/1536050#M72793</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2024-09-06T19:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox: hasBeenValidated vs altered</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-hasbeenvalidated-vs-altered/m-p/1536412#M72798</link>
      <description>&lt;P&gt;TLDR: &lt;STRONG&gt;altered&lt;/STRONG&gt; checks for None, &lt;STRONG&gt;hasBeenValidated&lt;/STRONG&gt; checks for errors, and both are decided during updateParameters()&lt;/P&gt;&lt;P&gt;Long explanation below:&lt;/P&gt;&lt;P&gt;Ok, here's how I understand it.&lt;/P&gt;&lt;P&gt;I have a tool with 3 parameters: param0, param1, param2.&lt;/P&gt;&lt;P&gt;param0 is going to act as a switch for the filter in param0: if it's "Y", give me one list, if it's "N" give me another list, and then I'm being lazy so I'm not going to set behaviour for anything else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;param1 is just a pick-one list, and param2 is just there for me to add a message to it.&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;LI-CODE lang="python"&gt;    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
                                displayName="Param0",
                                name="param0",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")
        # param0.value = "N"
        
        param1 = arcpy.Parameter(
                                displayName="Param1",
                                name="param1",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")        
        param2 = arcpy.Parameter(
                                displayName="Param2",
                                name="param2",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")      
        
        params = [param0, param1, param2]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        param0 = parameters[0]
        param1 = parameters[1]
        param2 = parameters[2]
        
        if param0.value == "Y":
            param1.filter.list = ["apple", "pear"]
        elif param0.value == "N":
            param1.filter.list = ["strawberry", "pineapple"]
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        param0 = parameters[0]
        param1 = parameters[1]
        param2 = parameters[2]
        
        if param0.altered:
            param0.setWarningMessage("param0 is altered")
        else:
            param0.setWarningMessage("param0 is not altered")
        
        if param1.hasBeenValidated:
            param2.setWarningMessage("param1 is validated, yeah")
        else:
            param2.setWarningMessage("param1 is not validated yet")
        
        
        return&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;What I've found by experimenting this morning is that I could only really get something useable for&amp;nbsp;&lt;STRONG&gt;altered&lt;/STRONG&gt; and&amp;nbsp;&lt;STRONG&gt;hasBeenValidated&lt;/STRONG&gt; in updateMessages(), so that's what this example is going to use.&lt;/P&gt;&lt;P&gt;I'm not sure if that's always true, but it does stand to reason that hasBeenValidated is only helpful after updateParameters(), since that's when validation happens.&lt;/P&gt;&lt;P&gt;It goes: getParameterInfo()--&amp;gt;updateParameters()--&amp;gt;updateMessages(), in that order. updateParameters() gets called when you make any chance, and updateMessages() is called immediately after.&lt;/P&gt;&lt;P&gt;In any case, here's what I think the difference is.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;altered:&lt;/STRONG&gt; Is the parameter's current value different from &lt;STRONG&gt;None&lt;/STRONG&gt;? This includes setting the default value, which is kind of dumb but whatever.&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 getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
                                displayName="Param0",
                                name="param0",
                                datatype="GPString",
                                parameterType="Required",
                                direction="Input")
        # param0.value = "N" # Set the default, if you want.
        params =[param0]
        return params

    def updateMessages(self, parameters):
        param0 = parameters[0]
        if param0.altered:
            param0.setWarningMessage("param0 is altered")
        else:
            param0.setWarningMessage("param0 is not altered")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1725888773534.gif" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114577iD83E23C6BAACECF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="AlfredBaldenweck_0-1725888773534.gif" alt="AlfredBaldenweck_0-1725888773534.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I've set the default:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_1-1725888805751.gif" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114578i8DA434B11E2CDA8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="AlfredBaldenweck_1-1725888805751.gif" alt="AlfredBaldenweck_1-1725888805751.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;hasBeenValidated&lt;/STRONG&gt;: Is there are error on the parameter?&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 updateParameters(self, parameters):
        param0 = parameters[0]
       
        if param0.value == "Y":
            param1.filter.list = ["apple", "pear"]
        elif param0.value == "N":
            param1.filter.list = ["strawberry", "pineapple"]
        return

    def updateMessages(self, parameters):
        param1 = parameters[1]
        param2 = parameters[2]
        
        if param1.hasBeenValidated:
            param2.setWarningMessage("param1 is validated, yeah")
        else:
            param2.setWarningMessage("param1 is not validated yet")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_2-1725889015417.gif" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/114579i2B66C56A3F25B004/image-size/large?v=v2&amp;amp;px=999" role="button" title="AlfredBaldenweck_2-1725889015417.gif" alt="AlfredBaldenweck_2-1725889015417.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 13:47:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-hasbeenvalidated-vs-altered/m-p/1536412#M72798</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-09-09T13:47:15Z</dc:date>
    </item>
  </channel>
</rss>

