AnsweredAssumed Answered

Field mappings remove field on a joined layer

Question asked by MollyKFoley on Apr 10, 2019
Latest reply on Apr 10, 2019 by MollyKFoley

Can you remove a field on a joined layer? I am trying to remove some fields before exporting the dataset, but it won't allow me to do so. The fields I am attempting to remove are the joined fields. The only work around I have to this would be to create a selection on the joined layer that selects all the records, remove the join, then export the data. I cannot use Join Field because this should technically be an "invisible" join - I am only joining the tables because I need to filter the data before exporting as the original data are related tables; I don't actually need any of the joined fields in the output.

 

mgmtJoin = arcpy.AddJoin_management(tractLyr, 'MgmtTractID', MgmtTractAttrbTV, 'MgmtTractID', 'KEEP_COMMON')

fieldmappings = arcpy.FieldMappings()
#This is the target feature class of the join. I joined a table to this feature class.
fieldmappings.addTable(tractFC)
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_OBJECTID"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_MgmtTractID"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_FocalRefID"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_StateID"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_VegMgmtPractice"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_Herbicide"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_MonthTreated"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_YearTreated"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_ImplementedBy"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_FundedBy"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_FarmBillCode"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_Comments"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_Area_Acres"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_DateAdded"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_Contract_Number"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("MgmtTractAttrb_CLU_Number"))

arcpy.FeatureClassToFeatureClass_conversion(tractLyr, exportPath, "MgmtTracts", "#", fieldmappings)
arcpy.RemoveJoin_management(tractLyr)

Outcomes