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 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddJoin_management<SPAN class="punctuation token">(</SPAN>tractLyr<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MgmtTractID'</SPAN><SPAN class="punctuation token">,</SPAN> MgmtTractAttrbTV<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MgmtTractID'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'KEEP_COMMON'</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FieldMappings<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#This is the target feature class of the join. I joined a table to this feature class.</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>addTable<SPAN class="punctuation token">(</SPAN>tractFC<SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_OBJECTID"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_MgmtTractID"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_FocalRefID"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_StateID"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_VegMgmtPractice"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_Herbicide"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_MonthTreated"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_YearTreated"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_ImplementedBy"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_FundedBy"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_FarmBillCode"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_Comments"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_Area_Acres"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_DateAdded"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_Contract_Number"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
fieldmappings<SPAN class="punctuation token">.</SPAN>removeFieldMap<SPAN class="punctuation token">(</SPAN>fieldmappings<SPAN class="punctuation token">.</SPAN>findFieldMapIndex<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"MgmtTractAttrb_CLU_Number"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureClassToFeatureClass_conversion<SPAN class="punctuation token">(</SPAN>tractLyr<SPAN class="punctuation token">,</SPAN> exportPath<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"MgmtTracts"</SPAN><SPAN class="punctuation token">,</SPAN> "<SPAN class="comment token">#", fieldmappings)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RemoveJoin_management<SPAN class="punctuation token">(</SPAN>tractLyr<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>