AnsweredAssumed Answered

FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap

Question asked by soldous on Jan 26, 2016
Latest reply on Jan 26, 2016 by rastrauch

Hi

I have a layer named patro_join with 114 fields and I want to preserve only two fields ("Layer","Text") in this layer. I tried to use FieldMappings but it removed only a half of fields and 57 fields still stay in the layer. I don´t know what is wrong. Here is my part of code:

 

fieldmappings = arcpy.FieldMappings()

fieldmappings.addTable("patro_join")

i=0

for field in fields:

      if field.getInputFieldName(0) == "Layer":

           print field.getInputFieldName(0)

     elif field.getInputFieldName(0) == "Text":

           print field.getInputFieldName(0)

     else:

           print field.getInputFieldName(0)

           fieldmappings.removeFieldMap(i)

           i=i+1

 

Can anyone help me please?

Outcomes