Select to view content in your preferred language

Reference joined field name in Model Builder

5102
5
Jump to solution
10-29-2013 08:41 AM
NealBanerjee
Frequent Contributor
Hello,

I have built a model in Model Builder for a specific use that accepts a feature class and table as input parameters, join them together based on known fields, and then runs some operations including running 'statistics' and field calculations.  The individual field names in the tables are/will be the same, however, the input feature class and table names may vary.  The problem Im having is when I run in model builder, I get errors because it appends the feature class and/or table names to the raw field name (e.g. <table name>.<field name>) which change based on input feature class/table names selected by user. 

I tried unchecking the 'Maintain fully qualified names' in the Environment settings for field, but I still get same errors.  I may not be setting it correctly - I tried setting Environment in the model and at the default ArcToolbox level.  Even after I do this the 'statistics' tool seems to still require the full qualified name.

Is there a trick to setting the Environment variable or is there another way for some of Model Builder to handle variable feature/table names for these tools?

Thanks

Neal
0 Kudos
1 Solution

Accepted Solutions
NealBanerjee
Frequent Contributor
I figured out a solution to my problem.  You can use the 'Parse Path' tool under the 'Insert'/'Model Only Tools' menu in Model Builder to extract the base name of the input feature class and store it as a variable.  Then when using 'Calculate Field' on a joined table, you can refer to the base name of the input field with the stored inline variable.  Below is an example.  In this example Im joining a user specified "Subbasins" feature class with a "hydrostrms" feature class, and then calculating the "CumDrnArMi" in "Subbasins" field based on an existing field in "hydrostrms".  Since the "Subbasins" is a user specified, the actual name of the feature class may vary.

The Model Builder image shows the 'Parse Path' tool used to extract base name of parameter input for "Subbasin" and store it as "nmSubbasin".  The field calculator image shows how field name of the joined table is specified with in-line variable substitution using %nmSubbasin%. 

[ATTACH=CONFIG]29155[/ATTACH]

[ATTACH=CONFIG]29158[/ATTACH]

View solution in original post

5 Replies
DuncanHornby
MVP Notable Contributor
Neal,

I know exactly the problem you are describing and have never been able to find a satisfactory solution to it, other than exposing the field name you are doing the calculation on and the expression as model parameters. This way you can change then accordingly for each run of your model.  This means you run your model as a normal tool rather than going into model builder to run it.

Duncan
0 Kudos
NealBanerjee
Frequent Contributor
Thanks Duncan - I hadnt thought of that route.  Im hoping there is a smoother alternative, but based doesnt sound like that is likely.

Thanks again
Neal
0 Kudos
NealBanerjee
Frequent Contributor
I figured out a solution to my problem.  You can use the 'Parse Path' tool under the 'Insert'/'Model Only Tools' menu in Model Builder to extract the base name of the input feature class and store it as a variable.  Then when using 'Calculate Field' on a joined table, you can refer to the base name of the input field with the stored inline variable.  Below is an example.  In this example Im joining a user specified "Subbasins" feature class with a "hydrostrms" feature class, and then calculating the "CumDrnArMi" in "Subbasins" field based on an existing field in "hydrostrms".  Since the "Subbasins" is a user specified, the actual name of the feature class may vary.

The Model Builder image shows the 'Parse Path' tool used to extract base name of parameter input for "Subbasin" and store it as "nmSubbasin".  The field calculator image shows how field name of the joined table is specified with in-line variable substitution using %nmSubbasin%. 

[ATTACH=CONFIG]29155[/ATTACH]

[ATTACH=CONFIG]29158[/ATTACH]
NealBanerjee
Frequent Contributor
I figured out a solution to my problem.  You can use the 'Parse Path' tool under the 'Insert'/'Model Only Tools' menu in Model Builder to extract the base name of the input feature class and store it as a variable.  Then when using 'Calculate Field' on a joined table, you can refer to the base name of the input field with the stored inline variable.  Below is an example.  In this example Im joining a user specified "Subbasins" feature class with a "hydrostrms" feature class, and then calculating the "CumDrnArMi" in "Subbasins" field based on an existing field in "hydrostrms".  Since the "Subbasins" is a user specified, the actual name of the feature class may vary.

The Model Builder image shows the 'Parse Path' tool used to extract base name of parameter input for "Subbasin" and store it as "nmSubbasin".  The field calculator image shows how field name of the joined table is specified with in-line variable substitution using %nmSubbasin%. 

[ATTACH=CONFIG]29155[/ATTACH]

[ATTACH=CONFIG]29157[/ATTACH]
0 Kudos
DuncanHornby
MVP Notable Contributor
Neal,

Excellent and thank you for sharing your solution! I would never have thought to use the parse tool. Definitely going to use that trick in future models.

Duncan
0 Kudos