Getting field map to update at runtime?

781
0
11-26-2019 07:13 AM
lah
by
New Contributor III

Hi all, 

I'm having quite a time with this one. I've built a model doing some linear/location referencing geoprocessing. It works fine, other than the fact that I need to run multiple feature classes through it, and there are two points within the model that I need the field maps to reset to default at runtime (table to table and append events). I've searched endlessly for a solution to this - and have mostly been referencing this thread: Field Mappings variable as a parameter not working in 10.5.1 . I actually got the table to table field map to reset using this method - calculate value to a field mappings object. Here is my code for that one: 

Expression:
getEvents("%JoinTable%")

Code:
def getEvents(intable):
            fms = arcpy.FieldMappings()

            fms.removeAll()
            fms.addTable(intable)
            return fms‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

However, when I try to do the exact same thing for the Append Events step, it fails with errors 000622 - parameters not valid and 000735 - Field map: value is required. I also tried this code for this step, which produced the same error.

Expression: 
getEvents("%TableTable%", "%PODS Line Events%")
 
Code:
def getEvents(intable, target):
            fms = arcpy.FieldMappings()
            tfields = arcpy.ListFields(target)
            tfnames = [f.name for f in tfields]
            
            fms.removeAll()
            fms.addTable(intable)
            
            for field in fms.fields:
                        if not field.name in tfnames:
                                    fmindex = fms.findFieldMapIndex(field.name)
                                    fms.removeFieldMap(fmindex)
            return fms

I also tried just adding the target table as the input, since Append Events just needs the schemas to match, and I also tried a few other combinations, but I cant seem to get it to work. Apologies in advance, my python knowledge is very limited to nonexistent. Hoping someone can help shed some light on this. I'm using ArcPro 2.4, also attaching some screenshots to show how they are kind of set up. 

Thank you!

0 Kudos
0 Replies