Deleting Global ID field

1785
2
11-20-2019 12:24 AM
LindsayRaabe_FPCWA
Occasional Contributor III

I've got a feature class that I am trying to remove the Global ID and editor information fields from. So far, the best way I can figure out is to create a new version of the feature class without the fields and append the data across. I've tried the following code I found online and tweaked, but am stuck on the field mapping. 

The input FC is "Prod_Temp" and I want the output to be "Prod_Sync". The fields listed in myfields are the fields in "Prod_Temp" that I want to retain. When I run the script, it complains about something around Line 10. I think I'm misunderstanding the input option for map.addInputField(existingFC, field). 

Any pointers?

# feature class I want to copy from
existingFC = (r"W:\TEMP\Prod_Temp.gdb\Prod_Temp")
# list of fields I want to keep (capitalization counts!)
myfields = ['FPCBusinessArea', 'Location', 'OpType', 'OperationStatus', 'Contractor', 'ContractorSupervisor', 'SupervisorPhone', 'FPCOIC', 'FPCOICPhone', 'Machinery', 'Comments', ]
# create an empty field mapping object
mapS = arcpy.FieldMappings()
# for each field, create an individual field map, and add it to the field mapping object
for field in myfields :
    map = arcpy.FieldMap()
    map.addInputField(existingFC, field)
    mapS.addFieldMap(map)
# copy the feature class using the fields you want
Prod_Sync = arcpy.FeatureClassToFeatureClass_conversion(existingFC, r"W:\TEMP\Prod_Sync.gdb", "Prod_Sync", "", mapS)
Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
2 Replies
LindsayRaabe_FPCWA
Occasional Contributor III

I haven't been able to figure this out. Created a work around where I have an empty template feature class and gdb stored locally that has only the fields I want to retain, and the python script now copies the template and appends the data to the copy. This is then used for the final upload process that I've been trying achieve (that didn't like the Global ID field). 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
RandyBurton
MVP Alum

I tried your code without issue.  An error at line 10 would suggest that either existingFC was not found or myfields contains a field name that is not in existingFC.

In either case the message would be:

RuntimeError: FieldMap: Error in adding input field to field map

You could add a section to read the fields in your feature, and if they are in your field list, then add them to the field map.

0 Kudos