1 Reply Latest reply on Jun 28, 2010 6:10 AM by clm42

    Python: ERROR 000728: Field LINK_TO does not exist within table

    geonetadmin
      Original User: BrendanM

      Hello

      I am writing a Python script that checks if a field exists in the table, adds the field if it doesn't and then calculates a value for the field. I receive an error message telling me that the field does not exist in the CalculateField function.

      4 things:
      1) Both Check A and Check B below tell me that the field is in the table.
      2) If I remove the table from ArcMap once the field has been added and then add it back, I am still told that the field does not exist.
      3) If I close ArcMap and re-open then the field is recognized and the script continues.
      4) If I add a field in a similar manner to a shapefile attribute table, the field is recognized and the script completes.

      Anyone have a solution, please? Thanks.

      Brendan Magill



      theFieldList = gp.ListFields(theBillingTable)

      theFlag = 0

      for eachField in theFieldList :

              if      str(eachField.Name) == "LINK_TO" :

                      theFlag = 1
                             
      if      theFlag == 0 :

              gp.AddField_management(theBillingTable,"LINK_TO","TEXT",3)

      theFieldList = gp.ListFields(theBillingTable)

      for eachField in theFieldList :

              if      str(eachField.Name) == "LINK_TO" :

                      gp.AddMessage("Yes, the field is in the table")    #Check A
                     
                      LinkToFld = str(eachField.Name)
                     
      gp.AddMessage(LinkToFld)         #Check B
           
      gp.CalculateField_management(theBillingTable,LinkToFld,"\"-\"","PYTHON")
        • Re: Python: ERROR 000728: Field LINK_TO does not exist within table
          clm42
          Well you can condense this a bit which may solve the problem.

          theFieldList = gp.ListFields(theBillingTable)
          fields=[]
          for field in the FieldList:
              fields.append(str(field.Name))
          if "LINK_TO" not in fields:
              gp.AddField_management(theBillingTable,"LINK_TO"," TEXT",3)
              gp.AddMessage("Added the field to the table")
              LinkToFld = "LINK_TO"
              gp.AddMessage(LinkToFld)
              gp.CalculateField_management(theBillingTable,LinkToFld,"\"-\"","PYTHON")
          else:
              gp.AddMessage("The field is already in the table")