AnsweredAssumed Answered

Is it possible to append ObjectID using fieldmappings?

Question asked by tpcolson on Jul 24, 2017
Latest reply on Jul 26, 2017 by bixb0012

Using Python 2.7.8, I'm trying to use the default field mappings for all fields except for 2 (PIC_ID and Object ID). The two tables are essentially identical, the tinkering with the globalid is something I have to do in order to preserve the globalid part of an attachment relationship when syncing an AGOL feature service to an on-premise SDE, and not something I'm looking to change. The below snippet works when I'm just altering one field out of the mapping: 

 

target_layer = "C:/blah blah blah.sde/blah.DBO.blah"
append_layer = renamefgdb+'\yada_yada_yada'
fieldmappings = arcpy.FieldMappings()

fieldmappings.addTable(target_layer)
fieldmappings.addTable(append_layer)

field_to_map_index = fieldmappings.findFieldMapIndex("globalid")

field_to_map = fieldmappings.getFieldMap(field_to_map_index)
field_to_map.addInputField(append_layer, "PIC_ID")

fieldmappings.replaceFieldMap(field_to_map_index, field_to_map)

arcpy.Append_management(append_layer, target_layer, "NO_TEST", fieldmappings, "")

However I have an operational requirement to maintain the objectid during append: that is, the objectID's coming from the append source need to be the same when they go to the target layer. 

 

But when I do something like this, or many many many variations thereof, it fails. 

target_layer = "C:/blah blah blah.sde/blah.DBO.blah"
append_layer = renamefgdb+'\yada_yada_yada'
fieldmappings = arcpy.FieldMappings()

fieldmappings.addTable(target_layer)
fieldmappings.addTable(append_layer)

field_to_map_index = fieldmappings.findFieldMapIndex("globalid")
field_to_map_index = fieldmappings.findFieldMapIndex("objectid")

field_to_map = fieldmappings.getFieldMap(field_to_map_index)
field_to_map.addInputField(append_layer, "PIC_ID")
field_to_map.addInputField(append_layer, "OBJECTID")

fieldmappings.replaceFieldMap(field_to_map_index, field_to_map)

 

So is it possible to add ObjectID to a field mapping in python, and if so, how?

Outcomes