<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Merge ignoring input FieldMappings object? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/merge-ignoring-input-fieldmappings-object/m-p/1545854#M27424</link>
    <description>&lt;P&gt;On Pro 3.3.2. Hello, I've been using custom python tools to standardize data for a few years. Recently, the Merge rule&amp;nbsp; seems to be ignoring the input FieldMappings object. Print statements indicate the field maps are being created properly, there are no issues in schema (these are fixed in script)... Please let me know if you notice anything I'm missing or have wrong in the following snippet. Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;printMessage(f"Creating FieldMappings for {fmaps_flag} fields")
f_Mappings = arcpy.FieldMappings()
f_Mappings.addTable(st_class)

wait_flag = False
for s_field, param in c_dict.items():
    #Skip if waiting for paired field
    if wait_flag: 
        param = c_dict[s_field[:-1] + 'L']
        wait_flag = False
    #Check if L field has a matching R field
    elif s_field[-1:] == 'L' and param and not c_dict[s_field[:-1] + 'R']:
        wait_flag = True
    if param:
        field_map_index = f_Mappings.findFieldMapIndex(s_field)
        fieldMap = f_Mappings.getFieldMap(field_map_index)
        fieldMap.addInputField(rc, param)
        fieldMap.mergeRule = 'First'
        f_Mappings.replaceFieldMap(field_map_index, fieldMap)
        arcpy.AddMessage(f"{param:&amp;lt;18}---&amp;gt;     {s_field}")

for fmap in f_Mappings.fieldMappings:
    outp = fmap.outputField.name
    if c_dict[str(outp)]: arcpy.AddMessage(f"{outp} input field:  {fmap.getInputFieldName(fmap.findInputFieldIndex(rc, c_dict[str(outp)]))}")
    
printMessage("Preparing Data for Merge")
#Pre-merge calculations for non-Douglas counties
inpt = [st_class, rc]
if fmaps_flag:
    #Douglas is submitting files that do not allow null values
    if "Douglas" not in county:
        arcpy.AddMessage("Calculating Fields (Pre-merge)...")  
        calcFields(rc, c_dict, False)
    arcpy.AddMessage("Merging data...")
    arcpy.management.Merge(inpt, merge_path, field_mappings=f_Mappings)     
else:
    arcpy.AddMessage("WARNING: No FieldMappings...")
    arcpy.AddMessage("Merging data without field mappings...")
    arcpy.Merge_management([st_class, rc], merge_path)
arcpy.AddMessage("Merge Complete!")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Oct 2024 21:32:54 GMT</pubDate>
    <dc:creator>AlexPetzold_OEM</dc:creator>
    <dc:date>2024-10-04T21:32:54Z</dc:date>
    <item>
      <title>Merge ignoring input FieldMappings object?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merge-ignoring-input-fieldmappings-object/m-p/1545854#M27424</link>
      <description>&lt;P&gt;On Pro 3.3.2. Hello, I've been using custom python tools to standardize data for a few years. Recently, the Merge rule&amp;nbsp; seems to be ignoring the input FieldMappings object. Print statements indicate the field maps are being created properly, there are no issues in schema (these are fixed in script)... Please let me know if you notice anything I'm missing or have wrong in the following snippet. Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;printMessage(f"Creating FieldMappings for {fmaps_flag} fields")
f_Mappings = arcpy.FieldMappings()
f_Mappings.addTable(st_class)

wait_flag = False
for s_field, param in c_dict.items():
    #Skip if waiting for paired field
    if wait_flag: 
        param = c_dict[s_field[:-1] + 'L']
        wait_flag = False
    #Check if L field has a matching R field
    elif s_field[-1:] == 'L' and param and not c_dict[s_field[:-1] + 'R']:
        wait_flag = True
    if param:
        field_map_index = f_Mappings.findFieldMapIndex(s_field)
        fieldMap = f_Mappings.getFieldMap(field_map_index)
        fieldMap.addInputField(rc, param)
        fieldMap.mergeRule = 'First'
        f_Mappings.replaceFieldMap(field_map_index, fieldMap)
        arcpy.AddMessage(f"{param:&amp;lt;18}---&amp;gt;     {s_field}")

for fmap in f_Mappings.fieldMappings:
    outp = fmap.outputField.name
    if c_dict[str(outp)]: arcpy.AddMessage(f"{outp} input field:  {fmap.getInputFieldName(fmap.findInputFieldIndex(rc, c_dict[str(outp)]))}")
    
printMessage("Preparing Data for Merge")
#Pre-merge calculations for non-Douglas counties
inpt = [st_class, rc]
if fmaps_flag:
    #Douglas is submitting files that do not allow null values
    if "Douglas" not in county:
        arcpy.AddMessage("Calculating Fields (Pre-merge)...")  
        calcFields(rc, c_dict, False)
    arcpy.AddMessage("Merging data...")
    arcpy.management.Merge(inpt, merge_path, field_mappings=f_Mappings)     
else:
    arcpy.AddMessage("WARNING: No FieldMappings...")
    arcpy.AddMessage("Merging data without field mappings...")
    arcpy.Merge_management([st_class, rc], merge_path)
arcpy.AddMessage("Merge Complete!")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 21:32:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merge-ignoring-input-fieldmappings-object/m-p/1545854#M27424</guid>
      <dc:creator>AlexPetzold_OEM</dc:creator>
      <dc:date>2024-10-04T21:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Merge ignoring input FieldMappings object?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merge-ignoring-input-fieldmappings-object/m-p/1548380#M27430</link>
      <description>&lt;P&gt;bug, in product plan to be fixed&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en-us/bug/when-using-the-merge-tool-in-arcpy-the-field-mappings-a-bug-000171352" target="_blank"&gt;BUG-000171352 for ArcGIS Pro (esri.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 10:03:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merge-ignoring-input-fieldmappings-object/m-p/1548380#M27430</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-10-14T10:03:11Z</dc:date>
    </item>
  </channel>
</rss>

