Using the Field Mapping data type as a parameter for a script tool?

648
2
08-21-2019 04:14 PM
ShaneReed
New Contributor

Hello,

I am trying to create a script tool, and I'd like to use the Field Mappings data type for my 2nd parameter (1st parameter is a Feature Class, Table, etc.).   It seems like this type of parameter should have the Obtained from property enabled, but I cannot find a data type, for use with the 1st parameter, that enables the Obtained from property.

 

While trying to troubleshoot the issue, I place code in the updateParameters validation function that logs debug messages to a text file.  When I try to find the data type of the Field Mappings parameter, using the type() function with self.params[1].value or self.params[1], I get: <type 'NoneType'>.

Can someone please explain how to use the Field Mapping data type with a script tool?  Specifically, I'd like to know how to populate the control associated with the Field Mappings data type.

Thank you

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

field mapping might be derived from the featureclass/table since more that one field is potentially involved.  See if that enables the fields

Setting script tool parameters—Geoprocessing and Python | ArcGIS Desktop 

0 Kudos
ShaneReed
New Contributor

I assume you're referring to the 1st parameter...I've tried feature class, table, table view, etc., but no luck.

I am able to use the 1st (data type is FC) and the code below, placed in the updateParameters function, to initialize a FieldMapping object:

...

if self.params[0].altered:
    fc = self.params[0].value
    fms = arcpy.FieldMappings()
    fms.addTable(fc)

...

After the code above runs, I can iterate over fms to confirm that it has a collection of valid FieldMap objects

0 Kudos