AnsweredAssumed Answered

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

Question asked by geonetadmin on Jun 25, 2010
Latest reply on Jun 28, 2010 by clm42
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")

Attachments

Outcomes