Select to view content in your preferred language

Help with "If Field Exists" in Modelbuilder

227
2
08-06-2024 02:34 PM
gmaurer1123
Emerging Contributor

Hello all, 

So, I have this model, and so far, it runs pretty well (rare anomalous failure here and there).

gmaurer1123_2-1722978407181.png

 

However, because of updates to the source data I need to get this model to run with an "If Field Exists" logic. Basically, I want the model to iterate though some feature classes, and if a field exists, I want it to calculate another field and continue on with the downline processes. If the field does not exist, I want the model to add the field, then calculate the field and continue on with downline processes. I've set both True and False as preconditions for the processes I want them to carry out, but nothing downline will validate. 

gmaurer1123_1-1722978298627.png

And if I try to reconnect the output (i.e. "Selections") to the "Add Field" tool, the model will validate but will generate an empty output because all the Inputs are not current. 

gmaurer1123_3-1722978683075.png

I'm lost in the sauce over here. Please help! Thank you!

 

 

0 Kudos
2 Replies
AlfredBaldenweck
MVP Regular Contributor

To clarify, you want to check if FieldA exists, then calculate it if it does, OR add, then calculate it?

Doesn't Field Calculator just create the field if it doesn't already exist?

0 Kudos
PaulMason
Emerging Contributor

I was really hoping to find an answer here because I'm having a similar issue with Extract Values to Points. That is, after the first run the field "RASTERVALU" exists and triggers an error for the next run. I would like to check if the field exists and if it does, skip the extract values function and move to the next step.
Initially, and ideally, I was hoping to find a way to make this function just overwrite an existing field (but this does not seem to be an option) since any pre-existing data, in my case, would have been edited by the rest of the modelbuilder code (e.g. Nulls removed).

0 Kudos