title: Passing parameters in the arcgis toolbox
body: <p>I'm trying to put some functioning code into a python toolbox in arcgis (Python 2.7).
  I've run the code externally using arcpy.
  I've setup a new python toolbox, edited a single parameter, a string with a site code e.g. SiteX.
  This should set the default online_id to &quot;SiteX&quot; and the SiteCode to &quot;SiteX20&quot;.</p>
  <p>The messages list all the feature classes but it is not liking <code>arcpy.AssignDefaultToField_management()</code>:</p>
  <pre><code>class Tool(object):
      def __init__(self):
          &quot;&quot;&quot;Define the tool (tool name is the name of the class).&quot;&quot;&quot;
          self.label = &quot;Tool&quot;
          self.description = &quot;&quot;
          self.canRunInBackground = False
  
      def getParameterInfo(self):
          &quot;&quot;&quot;Define parameter definitions&quot;&quot;&quot;
  
          param0 = arcpy.Parameter(
              displayName=&quot;Site Code&quot;,
              name=&quot;online_id&quot;,
              # datatype=&quot;Field&quot;,
              datatype=&quot;GPString&quot;,
              # parameterType=&quot;Optional&quot;,
              parameterType=&quot;Required&quot;,
              direction=&quot;Input&quot;)
  
          params = [param0]
          # params = None
          return params
  
      def isLicensed(self):
          &quot;&quot;&quot;Set whether tool is licensed to execute.&quot;&quot;&quot;
          return True
  
      def updateParameters(self, parameters):
          &quot;&quot;&quot;Modify the values and properties of parameters before internal
          validation is performed.  This method is called whenever a parameter
          has been changed.&quot;&quot;&quot;
          return
  
      def updateMessages(self, parameters):
          &quot;&quot;&quot;Modify the messages created by internal validation for each tool
          parameter.  This method is called after internal validation.&quot;&quot;&quot;
          return
  
      def execute(self, parameters, messages):
  
  
          online_id = parameters  # user request required
          # online_id = arcpy.GetParameterAsText(online_id)
          # online_id = raw_input('Enter your value :')
          dateyr = time.strftime(&quot;%y&quot;, time.localtime())
          sitecode = str(online_id) + str(dateyr)
  
          arcpy.env.workspace = arcpy.env.workspace + &quot;\\survey&quot;
  
          fclist = arcpy.ListFeatureClasses()
          arcpy.AddMessage(arcpy.env.workspace)
          arcpy.AddMessage(online_id)
          arcpy.AddMessage(sitecode)
  
          # Loop through all the feature classes and assign the default value for online_id
          for fc in fclist:
              arcpy.AddMessage(fc)
              arcpy.AddMessage(&quot;{0} has {1} features.&quot;.format(fc, online_id))
              arcpy.AssignDefaultToField_management(in_table=fc, field_name=&quot;online_id&quot;, default_value=online_id)
              # arcpy.AssignDefaultToField_management(in_table=fc, field_name=&quot;site_code&quot;, default_value=sitecode)
  
          return
  </code></pre>
  <p>Edit</p>
  <p>The error message given by arcgis:</p>
  <pre class="lang-none prettyprint-override"><code>Executing: Tool X
  Start Time: Tue Oct 06 15:57:33 2020
  Running script Tool...
  S:\PROJECTS\Workflow\GN_Coding\OA\03 GIS Projects - Coding Review\Geodatabase\DRS_survey_data.gdb\survey
  [&lt;geoprocessing parameter object object at 0x50DF5FC0&gt;]
  [&lt;geoprocessing parameter object object at 0x50DF5FC0&gt;]20
  drafting_ply
  drafting_ply has [&lt;geoprocessing parameter object object at 0x50DF5FC0&gt;] features.
  
  Traceback (most recent call last):
    File &quot;&lt;string&gt;&quot;, line 75, in execute
    File &quot;c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py&quot;, line 3574, in AssignDefaultToField
      raise e
  RuntimeError: Object: Error in executing tool
  
  Failed to execute (Tool).
  Failed at Tue Oct 06 15:57:40 2020 (Elapsed Time: 7.53 seconds)
  </code></pre>