I am testing out some code in the Python window of ArcGIS so that I can insert it into a standalone script later. I want to create a copy of a table and add a new field that is the result of concatenating two of the existing fields using a space as a delimiter.
I am sort of following the suggestion below to use field mapping which is from this page http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000065000000 because I ultimately want to use the JoinField command to join two tables based on two attributes: "To merge two or more fields in the join table before the join, first export the table or feature class using the Table To Table tool and merge using the tool's field map."
My code does the concatenation or merging just fine, but I cannot get it to rename the output field. In my resulting table, the name of the new field is the same as the first field I add to the fieldmap (ie, "COC_NAME" in the code below.)
fieldMappings = arcpy.FieldMappings() fieldmap_join = arcpy.FieldMap() fieldmap_join.joinDelimiter = " " fieldmap_join.mergeRule = "Join" fieldmap_join.addInputField("COC_DATA", "COC_NAME") fieldmap_join.addInputField("COC_DATA", "GRID_ID") fieldjoin = fieldmap_join.outputField fieldjoin.name = "JOINID" fieldmap_join.outputField = fieldjoin fieldMappings.addTable("COC_DATA") fieldMappings.addFieldMap(fieldmap_join) arcpy.TableToTable_conversion("COC_DATA", "C:\\HEA_GIS.mdb", "COC_MOD", "", fieldMappings)
Can someone point out what am I doing incorrectly or perhaps provide another solution?