AnsweredAssumed Answered

Error 000539: Invalid Field

Question asked by vshah6 on Mar 19, 2018
Latest reply on Mar 19, 2018 by vshah6



So I am first running a summary statistics to get the information I need and then the next step of the tool is to modify the table fields so I can get the field alias I want. This is done by creating new fields, doing calculations, etc. Here is my code:


import arcpy
import os
import arcpy.mapping as map
from arcpy import env
import datetime

arcpy.env.overwriteOutput = True

fiberFeatures = r'sdm_Fiber Segments'
date =
reportsGDB = r'C:\Users\vshah\Desktop\Test Folder\test_output.gdb'
reportsFolder = r'C:\Users\vshah\Desktop\Test Folder'

inLayer = fiberFeatures
outputName = 'fiber_summary'
outLayer = reportsGDB + "/" + outputName
statsFields = [["Feet", "SUM"], ["Miles", "SUM"]]
caseFields = ["NetworkID", "ProjectID"]

arcpy.Statistics_analysis(inLayer, outLayer, statsFields, caseFields)

in_table = reportsGDB +"\\" + 'fiber_summary'
deleteField = "FREQUENCY"

fieldList = arcpy.ListFields(in_table)
length = len(fieldList) - 2  ##subtracting 2 to account for the field being deleted when the modification is executed and to not count the Object ID field.

arcpy.DeleteField_management(in_table, deleteField)

alias_dict = {1: 'Network ID', 2: 'Project ID', 3: 'Total Feet', 4: 'Total Miles'}

for i, field in enumerate(fieldList):
    if field.type != 'OID' and i <= length:
        newfield = '{}new'.format(
        arcpy.AddField_management(in_table, newfield, field.type, field.precision,
                                field.scale, field.length, alias_dict[i], field.isNullable, field.required, field.domain)
        arcpy.CalculateField_management(in_table, newfield, '!{}!'.format(, "PYTHON_9.3")


After this will be a simple export to excel sheet. However when I get to this portion of the script, I get ERROR 000539: Invalid field FREQUENCY even though it is being deleted before it gets to creating new fields. Any thoughts on how to solve this or any help you can offer?