<?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 Setting parameter values in ToolValidator Class in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/setting-parameter-values-in-toolvalidator-class/m-p/95544#M3315</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In version 9.3.1. I'm building af script tool where some of the parameters have Data Type "Field" and with a Field-Filter limiting the allowed types (text, float etc.) and where the field names are "Obtained from" a Feature Layer given in a preceding parameter. This works OK in itself. Then I build a ToolValidator class for this tool in which I populate these field parameters with a string containing a valid field name from the same feature layer. This doesn't work. The field parameters gets a red errormark and the error text: "Invalid field type" - except for the fields of type "long integer"!?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can see in the documentation, that when you read parameter values using "self.params&lt;I&gt;.Value" you may have to convert the obtained value to a string before using it. What I am writing to the value is a string, and it may have to be a field object or a field name object. How do I make that?&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My current code fragment is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if self.params[1].Altered and self.params[1].Value and not self.params[1].HasBeenValidated:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LayerLayer = self.params[1].Value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if self.GP.exists(LayerLayer):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; desc = self.GP.describe(LayerLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; datasettype = desc.DatasetType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if datasettype.lower() == "featureclass":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; layertype = desc.ShapeType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if layertype.lower() == "point":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; # Check for a match with standard names&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fieldlist = self.GP.ListFields(LayerLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; standardlist = ["Z","ProfileNam","Comment","Quality","UserName","ChangeDate"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for i in range(len(standardlist)):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for candidatefield in fieldlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if candidatefield.name.upper() == standardlist&lt;I&gt;.upper():&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; self.params[i+2].Value = candidatefield.name&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Apr 2010 13:15:35 GMT</pubDate>
    <dc:creator>deleted-user-wJESCgrAq9zI</dc:creator>
    <dc:date>2010-04-14T13:15:35Z</dc:date>
    <item>
      <title>Setting parameter values in ToolValidator Class</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/setting-parameter-values-in-toolvalidator-class/m-p/95544#M3315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In version 9.3.1. I'm building af script tool where some of the parameters have Data Type "Field" and with a Field-Filter limiting the allowed types (text, float etc.) and where the field names are "Obtained from" a Feature Layer given in a preceding parameter. This works OK in itself. Then I build a ToolValidator class for this tool in which I populate these field parameters with a string containing a valid field name from the same feature layer. This doesn't work. The field parameters gets a red errormark and the error text: "Invalid field type" - except for the fields of type "long integer"!?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can see in the documentation, that when you read parameter values using "self.params&lt;I&gt;.Value" you may have to convert the obtained value to a string before using it. What I am writing to the value is a string, and it may have to be a field object or a field name object. How do I make that?&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My current code fragment is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if self.params[1].Altered and self.params[1].Value and not self.params[1].HasBeenValidated:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; LayerLayer = self.params[1].Value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if self.GP.exists(LayerLayer):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; desc = self.GP.describe(LayerLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; datasettype = desc.DatasetType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if datasettype.lower() == "featureclass":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; layertype = desc.ShapeType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if layertype.lower() == "point":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; # Check for a match with standard names&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fieldlist = self.GP.ListFields(LayerLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; standardlist = ["Z","ProfileNam","Comment","Quality","UserName","ChangeDate"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for i in range(len(standardlist)):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for candidatefield in fieldlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if candidatefield.name.upper() == standardlist&lt;I&gt;.upper():&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; self.params[i+2].Value = candidatefield.name&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Apr 2010 13:15:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/setting-parameter-values-in-toolvalidator-class/m-p/95544#M3315</guid>
      <dc:creator>deleted-user-wJESCgrAq9zI</dc:creator>
      <dc:date>2010-04-14T13:15:35Z</dc:date>
    </item>
  </channel>
</rss>

