Select to view content in your preferred language

Error in adding table to field mappings

1884
1
10-10-2013 08:36 AM
ionarawilson1
Deactivated User
This code works fine when I run in Arcmap but when I run the geoprocessing service I get the error:

"error in adding table to field mappings"
Does anybody know why this is happening?
Thanks!

arcpy.env.scratchWorkspace = "d:\\ArcGISData\\SARS\\Python_10April2013\\SARS.gdb"

with arcpy.da.UpdateCursor(Input_Polygons, ("DateStart", "PlanID", "FFY")) as rows:


       
    for row in rows:

        if not (row[1] or "").strip(): #covers blank, one blank space, or Null
           Datestarstr1 = row[0]

           Datestarstr2 = str(Datestarstr1)
       


           yearonly = Datestarstr2[0:4]

                 
           row[2] = yearonly


           rows.updateRow(row)   

# Create new field mappings and add both feature classes

fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(Input_Polygons)
fieldmappings.addTable(Counties)

# create output feature for spatial join
outstewardshipcounties = os.path.join(arcpy.env.scratchGDB, "StewardshipCounties")
arcpy.CalculateField_management(Input_Polygons, "OID", '!OBJECTID!', "PYTHON")
arcpy.CalculateField_management(Counties, "OID", '!OBJECTID!', "PYTHON")
#run spatial joint tool

arcpy.SpatialJoin_analysis(Input_Polygons, Counties, outstewardshipcounties , "#", "#", fieldmappings, "HAVE_THEIR_CENTER_IN")

#create dictionary

path_dict = { }
rows = arcpy.SearchCursor(outstewardshipcounties)
for row in rows:
    
    keyrow =  row.OID
    valrow = row.FIPS_TXT
    path_dict[keyrow] = valrow

urows = arcpy.UpdateCursor(Input_Polygons)
for urow in urows:

    upkey = urow.OID
    if upkey in path_dict:
        urow.setValue("County", path_dict[upkey])
        urows.updateRow(urow)
del row, rows, urow, urows
Tags (2)
0 Kudos
1 Reply
ionarawilson1
Deactivated User
I figured ArcGIS server was confused as to where the data was. Once I changed the variable values to parameters the errors disappeared but no features are being updated:

Input_Polygons = arcpy.GetParameterAsText(0)
Counties = arcpy.GetParameterAsText(1)
0 Kudos