Select to view content in your preferred language

How to evaluate NULL values in Field Script

1462
2
Jump to solution
03-01-2022 11:21 PM
LindsayRaabe_FPCWA
Honored Contributor

I'm trying to write a Field Script in my Network Dataset Properties that limits a Travel Modes ability to use edges that don't contain specific attributes. For example, a feature with a column called RAV3_NETWORK either contains a value "Tandem Drive Network 3" or is NULL. I want to prohibit a route from traversing edges where that field is NULL.

I have managed to get this Field Script to work: NOT([RAV3_NETWORK] = "Tandem Drive Network 3") where I have added in another random value instead of NULL, but I don't want to have to modify the data to do that.

I would rather use something like:

NOT([RAV3_NETWORK] = "Tandem Drive Network 3") OR [RAV3_NETWORK] IS NULL

which would find any value that isn't Tandem Drive Network 3 as well as return the Nulls - but I can't for the life of me get it to recognise Nulls. I've tried Empty, IsEmpty, IsNull as well with no luck. The above query returns this error in the Build Network log for each feature with a NULL value: 

SourceName: State_Road_Network, ObjectID: 354, Network object evaluator error.

LindsayRaabe_FPCWA_2-1646205622577.pngLindsayRaabe_FPCWA_3-1646205693940.png

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos
1 Solution

Accepted Solutions
AlanHatakeyama
Esri Contributor

You are correct that the function to check for Null values is the IsNull() function.  However, VBScript doesn't like comparing a Null value to a string (which is what you're doing in the first half of your OR statement if that field value happens to be Null).  To get around this, you will need to make a Code Block that does the Null check separately, and only if the field value is not Null, then move forward to do the string comparison:

Result:

r

Code Block:

r = False
If IsNull([RAV3_NETWORK]) Then
  r = True
ElseIf [RAV3_NETWORK] <> "Tandem Drive Network 3" Then
  r = True
End If

For the unequality check, I used the <> operator instead of using Not with the = operator, since I don't like how VBScript overloads the = operator for both comparison and assignment.

Let me know if you're still running into problems.  Thanks!

 

Alan

View solution in original post

2 Replies
AlanHatakeyama
Esri Contributor

You are correct that the function to check for Null values is the IsNull() function.  However, VBScript doesn't like comparing a Null value to a string (which is what you're doing in the first half of your OR statement if that field value happens to be Null).  To get around this, you will need to make a Code Block that does the Null check separately, and only if the field value is not Null, then move forward to do the string comparison:

Result:

r

Code Block:

r = False
If IsNull([RAV3_NETWORK]) Then
  r = True
ElseIf [RAV3_NETWORK] <> "Tandem Drive Network 3" Then
  r = True
End If

For the unequality check, I used the <> operator instead of using Not with the = operator, since I don't like how VBScript overloads the = operator for both comparison and assignment.

Let me know if you're still running into problems.  Thanks!

 

Alan

LindsayRaabe_FPCWA
Honored Contributor

@AlanHatakeyama That worked a charm. Thank you for your help. 

Lindsay Raabe
GIS Officer
Forest Products Commission WA
0 Kudos