+ Reply to Thread
Results 1 to 2 of 2

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

  1. #1
    Brendan Magill
    Join Date
    Jun 2010
    Posts
    5
    Points
    0
    Answers Provided
    0


    0

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

    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")
    Last edited by BrendanM; 06-25-2010 at 02:01 PM.

  2. #2
    Chris Mathers
    Join Date
    Apr 2010
    Posts
    370
    Points
    14
    Answers Provided
    2


    0

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

    Well you can condense this a bit which may solve the problem.

    Code:
    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")

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts