0

In the snippet of code below, I'm attempting to create variables, then pass them to the arcpy.JoinField_managment tool:

#Set join parameter variables
inFeatures = arcpy.GetParameterAsText(0)
inField = arcpy.GetParameterAsText(1)
joinTable = arcpy.GetParameterAsText(2)
joinField = arcpy.GetParameterAsText(3)
arcpy.MakeFeatureLayer_management(inFeatures,"inFeatures_lyr") #make feature layer from feature class
#Join road feature class to buffer distance table
arcpy.JoinField_management("inFeatures_lyr", inField, joinTable, joinField)    

The result appears to actually append the field values from joinTable to the attribute table in inFeatures_lyr. I've tried replacing the variables with hard-coded values and get the same result. I can't remove the join and and can only get the fields out by deleting them as I would any other field in the feature class. How do I structure this to create the join correctly, do my geoprocessing, then remove the join programmatically?

1

You are using the wrong tool. You are using Join Field, and you want to be using Add Join.

Join Field adds the fields to your dataset - it modifies your data.

Joins the contents of a table to another table based on a common attribute field. The input table is updated to contain the fields from the join table. You can select which fields from the join table will be added to the input table.

Add Join joins the two datasets the same way it does if you create a join within the ArcMap GUI.

Joins a layer to another layer or table (where layer is a feature layer, table view, or raster layer with a raster attribute table) based on a common field.

The records in the Join Table are matched to the records in the input Layer Name. A match is made when the input join field and output join field values are equal. This join is temporary.

You can then follow the Add Join with the Remove Join tool to remove it programmatically.

  • @SDRobinson This looks like a new question - I'd recommend asking as a new question. – Midavalo Jun 15 '17 at 14:28
  • Yes. That's what I'm going to do. – SD Robinson Jun 15 '17 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.