AnsweredAssumed Answered

Error 99999: Failed to execute (Addfield)

Question asked by Winn.McEnery_CDFW on Feb 25, 2020
Latest reply on Feb 25, 2020 by Dan_Patterson

I am trying to add multiple fields to an attribute table using the same attribute's tables current field names. I want the new fields to be text fields that can be populated with either yes or no later on. When I run the script below I get the error above. The script works halfway through and crashes. Any help or suggestions are welcome.

 

import arcpy
from arcpy import env

 

# To allow overwriting the outputs change the overwrite option to true.
arcpy.env.overwriteOutput = True

 

 

# ###############################################################################
# [1] Script adds duplicate (text) fields to attribute table with shortened name
# Allows for Yes and No values to be added to table

 

# Identify shapefile
blocks = r"C:\Users\Workspace\scrap\FB_CFDReport.shp"

 

# Generate list for each field in blocks
fields = arcpy.ListFields(blocks)

 

# For loop creates duplicate text fields in block shapefile
for field in fields:
    field4 = field.name
    f4 = field4[0:8] + "X"
    print(f4)
    arcpy.AddField_management(blocks, f4, "TEXT")

 

    #arcpy.SelectLayerByAttribute_management(blocks, selection_type="NEW_SELECTION", where_clause= field+ " > 0", invert_where_clause="")
    #arcpy.CalculateField_management(blocks, f4, 'Yes')
    #arcpy.SelectLayerByAttribute_management(blocks, selection_type="NEW_SELECTION", where_clause= field+" = 0", invert_where_clause="")
    #arcpy.CalculateField_management(blocks, f4, 'No')

Outcomes