The Check Is Not Actually Required If You are Going to Create The Field Anyhow
If you are going to create the field if it doesn't exist, you don't even need to check for its existence. If the field already exists, and you run arcpy.AddField_management()
for that same field, it will do nothing.
Similarly in ModelBuilder if you run the 'Add Field' tool, it will output a message warning that the field already exists, but it will continue on to the next step in the model just fine. (NB: If you do it with a different data type, it will fail, but so long as you use the same data type, it is fine.) Subsequent tools in the model that depend on that field should then be able to validate successfully, because the model can determine that the field will actually exist. Creating the field with a script tool will not allow the model to validate the existence of that field. So with your script tool method the model may be able to run successfully if you run it directly (ie, not in edit mode) but it won't be able to validate and run in edit mode.
I can't see this behaviour of the 'Add Field' tool and arcpy.AddField_management()
function documented anywhere, but I noticed it a while back and have found it to be useful.
Of course you would need to be confident that if the field already exists, that it will be of the correct data type, length, etc.
To confirm, I just ran the following code:
print "Adding new field first time"
arcpy.AddField_management(fc, "NewField", "TEXT")
print "Adding new field second time"
arcpy.AddField_management(fc, "NewField", "TEXT")
print "Adding new field third time"
arcpy.AddField_management(fc, "NewField", "TEXT")
and got the following output:
Adding new field first time
Adding new field second time
Adding new field third time
The new field was added to the fc
feature class and no errors were reported.
I then ran a model in ModelBuilder that adds a field that already exists and then does a Calculate Field on that same field and it worked fine. I got the output:
Executing (Add Field): AddField C:\Users\<username>\Documents\ArcGIS\Default.gdb\fc NewField TEXT # # # # NULLABLE NON_REQUIRED #
Start Time: Tue Aug 21 11:01:38 2018
WARNING 000012: NewField already exists
Succeeded at Tue Aug 21 11:01:38 2018 (Elapsed Time: 0.08 seconds)
Executing (Calculate Field): CalculateField C:\Users\<username>\Documents\ArcGIS\Default.gdb\fc NewField 'blah' PYTHON #
Start Time: Tue Aug 21 11:01:38 2018
Succeeded at Tue Aug 21 11:01:38 2018 (Elapsed Time: 0.12 seconds)
It's up to you whether you want to be extra safe and do the check anyhow, but at least in version 10.3.1 and 10.5.1 that I've used recently, it works fine this way. It's quite convenient behaviour (at least for this kind of scenario).
If a Field Existence Check Really Is Required
There are some situations when you really do need to check for the existence of a field (eg, you don't want to create a new field, but you do want to do something different depending on if the field exists or not). In this case, I use something like:
if len(arcpy.ListFields(fc, fieldName)):
# Field exists. Do something.
else:
# Field does not exist. Do something else.
Best Answer
When you wire up a script to a tool interface, the interface will have no knowledge of any layers created by the code itself, unless its an output parameter you have specified. As you are creating these layers in your code I would suggest you edit your code to utilise them as it is not possible to access something that does not yet exist.
So to answer your question I would say this is a configuration problem and you need to adapt your code.