I’m trying to build a Python Toolbox which uses a Field Mappings control (GPFieldMapping parameter). For some reason I don’t manage to get the same behaviour of the Field Mappings control as in the standard geoprocessing tools: Append, Merge …. On my tool, the context menu doesn’t show the Add Input Field command as it does in the Append tool (see print screen below). Any clues of why this might happen?

Please find below my code:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">Toolbox</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">__init__</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""</SPAN>
self<SPAN class="punctuation token">.</SPAN>label <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Toolbox"</SPAN>
self<SPAN class="punctuation token">.</SPAN>alias <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="comment token"># List of tool classes associated with this toolbox</SPAN>
self<SPAN class="punctuation token">.</SPAN>tools <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>TestFieldMappings<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">TestFieldMappings</SPAN><SPAN class="punctuation token">(</SPAN>object<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">__init__</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Define the tool (tool name is the name of the class)."""</SPAN>
self<SPAN class="punctuation token">.</SPAN>label <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Test Field Mappings"</SPAN>
self<SPAN class="punctuation token">.</SPAN>description <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
self<SPAN class="punctuation token">.</SPAN>canRunInBackground <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">getParameterInfo</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Define parameter definitions"""</SPAN>
prm_base_feature <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>displayName <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Base Feature Class'</SPAN><SPAN class="punctuation token">,</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">'BaseFeatureClass'</SPAN><SPAN class="punctuation token">,</SPAN>
datatype <SPAN class="operator token">=</SPAN> <SPAN class="string token">'DETable'</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Required'</SPAN><SPAN class="punctuation token">,</SPAN>
direction <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Input'</SPAN><SPAN class="punctuation token">)</SPAN>
prm_test_feature <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>displayName <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Test Feature Class'</SPAN><SPAN class="punctuation token">,</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">'TestFeatureClass'</SPAN><SPAN class="punctuation token">,</SPAN>
datatype <SPAN class="operator token">=</SPAN> <SPAN class="string token">'DETable'</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Required'</SPAN><SPAN class="punctuation token">,</SPAN>
direction <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Input'</SPAN><SPAN class="punctuation token">)</SPAN>
prm_field_mappings <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Parameter<SPAN class="punctuation token">(</SPAN>displayName <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Field Mappings'</SPAN><SPAN class="punctuation token">,</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">'FieldMappings'</SPAN><SPAN class="punctuation token">,</SPAN>
datatype <SPAN class="operator token">=</SPAN> <SPAN class="string token">'GPFieldMapping'</SPAN><SPAN class="punctuation token">,</SPAN>
parameterType <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Optional'</SPAN><SPAN class="punctuation token">,</SPAN>
direction <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Input'</SPAN><SPAN class="punctuation token">)</SPAN>
params <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>prm_base_feature<SPAN class="punctuation token">,</SPAN>
prm_test_feature<SPAN class="punctuation token">,</SPAN>
prm_field_mappings<SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># return parameters array </SPAN>
<SPAN class="keyword token">return</SPAN> params
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">isLicensed</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Set whether tool is licensed to execute."""</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">updateParameters</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""</SPAN>
<SPAN class="keyword token">if</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>altered <SPAN class="operator token">and</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>altered<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> <SPAN class="punctuation token">(</SPAN>parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>hasBeenValidated <SPAN class="operator token">and</SPAN> parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>hasBeenValidated<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
tmp_fms <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FieldMappings<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Create empty FieldMappings object</SPAN>
base_fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>valueAsText<SPAN class="punctuation token">)</SPAN> \
<SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>type <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Geometry'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Raster'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
test_fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>valueAsText<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>type <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Geometry'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Raster'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># loop base fields </SPAN>
<SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> base_fields<SPAN class="punctuation token">:</SPAN>
tmp_fm <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FieldMap<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
tmp_fm<SPAN class="punctuation token">.</SPAN>outputField <SPAN class="operator token">=</SPAN> f
<SPAN class="comment token"># loop test fields</SPAN>
<SPAN class="keyword token">for</SPAN> g <SPAN class="keyword token">in</SPAN> test_fields<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># if name matches, add the input field</SPAN>
<SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> g<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">:</SPAN>
tmp_fm<SPAN class="punctuation token">.</SPAN>addInputField<SPAN class="punctuation token">(</SPAN>parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>valueAsText<SPAN class="punctuation token">,</SPAN> g<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># add the field map</SPAN>
tmp_fms<SPAN class="punctuation token">.</SPAN>addFieldMap<SPAN class="punctuation token">(</SPAN>tmp_fm<SPAN class="punctuation token">)</SPAN>
parameters<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>value <SPAN class="operator token">=</SPAN> tmp_fms<SPAN class="punctuation token">.</SPAN>exportToString<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">updateMessages</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">execute</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> parameters<SPAN class="punctuation token">,</SPAN> messages<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""The source code of the tool."""</SPAN>
<SPAN class="keyword token">return</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Notes: I managed to make the Add Input Field show on my tool by using the initializing script of the Field Mappings in the getParameterInfo routine. This is of no use as I want the Field Mappings to be updated each time the input is changed