[GIS] Check if field value for selected features is null using ModelBuilder

arcgis-10.0modelbuilderpython

My feature class contains two fields: an identifying field U_ID, and a descriptive text field DESC. This field currently has <Null> for all features. I would like to select all the features with the same ID and populate this field with sequential values (using code I have previously used here), only if there are <Null> values in DESC.

My model receives the feature class as input into a Feature Selection Iterator, grouping by U_ID. I then want to check for null values in the DESC field for those Selected Features. If a <Null> is found in DESC for any of the Selected Features, return true and populate the field with values. If there are values for all the features, the condition is false.

This is what the model looks like:

enter image description here

For example: the iterator selects U_ID = AA01. There are ten features in the feature class with that ID, so Selected Features contains those 10 features. The Calculate Value tool contains the following:

checkIfNull("%DESC%")

def checkIfNull(f):
  return "true" if not f else "false"

Seeing as DESC is <Null> for those ten features (or even just one of the features), the precondition is true, and Calculate Field DESC should be executed. However, the precondition returns false and the model ends. Changing the code to

return "true" if f is None else "false"

yields the same result. I don't think I'm accessing the values in DESC correctly, because my test for <Null> seems to be right, judging by the answers to other questions here.

Best Answer

Using a Field Value Iterator in a submodel, I used the Selected Features as input and iterated over the ten values in the field. I had to set the Null value as Null:

enter image description here

and collect the values as a multivalue. In my main model, I then check that list and if it contains what I deemed as invalid values, it returns true.

isValid("%List%")

def isValid(l):
  try:
    map(int, l.split(";"))
    return "true"
  except:
    return "false"
Related Question