I'm joining a table to a layer file, calculating a field in the layer and then removing the join. The code below runs with no errors, but when I check the field in the attribute table, nothing has been updated. If I do this manually in ArcMap with Field Calculator, all is good. What am I missing?

checkds = 'AllCounties' # don't want to calculate values for this feature class
fields = {'FMCDL' : 'CityLeft', 'FMCDR' : 'CityRight'}
lyr = 'Working'
join_table = os.path.join(targetGDB, 'MunicipalCodes')
arcpy.MakeTableView_management(join_table, 'tblvw')
join_field = 'Code'
calcFrom = '!MunicipalCodes.Description!'
fds = 'Framework'
fclasses = getFeatureClasses(fds)

if fclasses: # make sure feature classes were returned
    if checkds in fclasses:
        fclasses.remove(checkds) # remove unwanted feature class

    for ds in fclasses: # each feature class
        working_lyr = ds #+ '_' + lyr # layer name must be unique for each feature class
        arcpy.MakeFeatureLayer_management(ds, working_lyr)

        for k, v in fields.iteritems(): # each  city left and right field
                print('\tAdding join...')
                arcpy.AddJoin_management(working_lyr, k, 'tblvw', join_field)
                arcpy.CalculateField_management(working_lyr, v, calcFrom, 'PYTHON_9.3')
  • 2
    Sometimes in a join the name of the layer is placed in front of the field name to distinguish from duplicates. In your calcFrom you may need to modify the name of the field to reflect this. Also, you may need to create a table view of your join_table. Here is an example: gis.stackexchange.com/questions/81365/… – dslamb Apr 8 '16 at 14:24
  • Just an idea, is join_table a Table View or just a path to a table? – Hornbydd Apr 8 '16 at 15:28
  • join_table was originally a path to the table in the same fgdb as the feature class, but per @dslamb I changed it to a table view as per the revised code above. Still not updating, though. – recurvata Apr 8 '16 at 16:08
  • The code is working now, current version above. Used both of @dslamb suggestions, that did the trick. If you want to post that as an answer I can mark it correct. – recurvata Apr 8 '16 at 19:06

The solution turned out to be making sure you have the table as a table view, and adding the name of the layer in front of the field name. These are shown in the example here:

How to Calculate Field in joined table using ArcPy?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.