Simpler way to use field mappings

06-01-2012 10:34 AM
Status: Open
MVP Esteemed Contributor
Field maps are very powerful but notoriously difficult to implement in ModelBuilder (using Calculate Value) and in Python script tools.

Field maps can be manipulated in ModelBuilder within the dialog for tools that use them (Append, Merge) but when a new dataset is applied to them any of those interactive changes are lost.

A "Simple Field Mapping"  tool perhaps could be used to do simple field map operations adding, dropping, and reordering fields. perhaps in the comments we could flesh out what such a tool could do.

Or, perhaps this need could be addressed with some creative new interfaces to the Field Mappings object that are less complicated, and some examples in the help on how to use them in ModelBuilder.
1 Comment
I agree--field maps are powerful and useful, but I have been particularly frustrated when trying to use them in Python scripts. Three principal problems stem from the verbose parameter structure:
  1. The "convert to Python code snippet" functionality does not introduce line breaks, and the lengthy parameter text causes a very, very wide line that must be laboriously reformated to make it all visible in the Python IDE on one screen without scrolling horizontally.
  2. The internal structure of the field map parameter is very poorly documented, making it difficult to write from scratch without using the "convert to Python code snippet" functionality.
  3. The format of the parameter is particularly awkward when used on a joined table, and even more so when the tables used in the join are themselves parameters supplied to the larger script. That is, the field map specifies fields by their fully qualified names ("a_certain_table.field_one"), but if the component table names are subject to change, the parameter must be written in Python as sz_table_name_variable + ".field_one" to allow the tool to operate correctly when "some_other_table" is used as input to the join instead of the original "a_certain_table".
If the field map could replace the fully-qualified field names with an unqualified field name together with an ordinal number indicating the table component it came from (omitted, or "1" for unjoined table input), using the tool in parameterized scripts would become much easier.