Another thought is that when testing field maps, I like to use a script tool and custom script tool behavior so I can visually inspect the field map instead of trying to decode the crazy long strings they produce.
Example ToolValidator
class I used to conclude that yes, replaceFieldMap
is required for it to be persisted in the parameter value:
class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parmater
has been changed."""
if (not self.params[0].hasBeenValidated
or not self.params[1].hasBeenValidated):
targetFeatures = self.params[0].value
joinFeatures = self.params[1].value
fieldMappings = arcpy.FieldMappings()
if targetFeatures:
fieldMappings.addTable(targetFeatures)
if joinFeatures:
fieldMappings.addTable(joinFeatures)
idx = fieldMappings.findFieldMapIndex("PRIORITY")
fieldMap = fieldMappings.getFieldMap(idx)
fieldMap.mergeRule = 'Sum'
fieldMappings.replaceFieldMap(idx, fieldMap)
self.params[3].value = fieldMappings.exportToString()
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return