I'm writing a script which takes, for its first two parameters, feature classes (or tables). For the third parameter, I want to provide the user with a field mapping option similar to what ArcMap uses for Append or Spatial Join, but I haven't been able to figure out how to add this functionality.
I found the data type "Field Mapping" in the tool properties, but I don't know how to get it to work. Help?
Edit: The original purpose of my tool is to copy the most recent inspection data from a related table into the parent table (the child table has multiple records for each record in the parent). I need the field mapping to help me know which fields from the child table to pull into equivalent fields in the parent table.
This is what I have:
# Based off code from: http://support.esri.com/technical-article/000011948 import arcpy def updateParent(fc1, fc1_fields, fc2, fc2_fields): ''' @param fc1 : feature class : The parent feature class, which we will update @param fc1_fields : list of field names : First name is date field, second is field to join, could modify code and add more fields to copy over @param fc2 : feature class or table : The child feature class, from which we will pull data @param fc2_fields : list of field names : See comments on second param, fields must be in the same order ''' # We want to update values in our first feature class cursor = arcpy.da.UpdateCursor(fc1, fc1_fields) for row in cursor: # Create a new date list for each value in fc1 date_list =  # Search all the values in fc2 cursor2 = arcpy.da.SearchCursor(fc2, fc2_fields) for row2 in cursor2: # If the value matches the currently selected on in fc1, add date to list if row == row2: date_list.append(row2) # Get the latest (maximum) date print max(date_list) most_recent_date = max(date_list) # Update row in fc1 based on that value row = most_recent_date cursor.updateRow(row) del row, cursor, row2, cursor2 # Define the workspace that will contain the two feature classes. arcpy.env.workspace = r"C:\GIS_Temp\Temp.gdb" #fc1 = arcpy.GetParameterAsText(0) # Parent feature class #fc2 = arcpy.GetParameterAsText(1) # Child feature class / table # This is where the problem is!!!! # I don't know how to get a field map as an input and I don't know how to extract the information once I have it. #fldmapping = arcpy.GetParameterAsText(2) # If I hardcode my script, I just give it lists with the fields in the correct order so that I know DATE = DATE and Name = PostName updateParent("TestRelateFC", ["DATE","Name"], "RelateTestTable2", ["DATE","PostName"])
Right now I'm only copying over DATE, but I would also like to be able to pull over the data that goes with that inspection date (like condition, etc.) The fields in the parent and child may not have the same name, which is why I need field mapping.
I assume I need to use updateParameters() in tool validation, but I don't know how it works for field mapping.