Handling NULL Dates in Labels

3723
5
Jump to solution
11-01-2012 08:31 AM
JamesCueno
New Contributor II
I've got an MXD I'd like to publish in 10.1, that worked fine at 10.0.  The problem is in the dynamic labels on some of the feature classes.  I want to use an advanced label with some vbscript formatting.  Some of the records have null values in a date field.  I'd like to skip lines in the label when they encounter a null value.  It works in ArcMap 10.1 and worked in Server 10.0, but Server 10.1 pukes and refuses to even draw the layer.

I've tried:
1) if [AnnexDate] <> "" then
2) if not isnull( [AnnexDate]) then
3) if len( [AnnexDate])>0 then
4) if [AnnexDate] >=  #01-01-1800 00:00:00# then

Maybe I'm just lucky with my data, but (miraculously) ArcMap likes all of them and (surprise!) Server doesn't.

I've run out of ways to sort out NULL dates.  Any suggestions?  Other than the obvious: "use Python instead".  I haven't had time to upgrade my skills to Python.  I am welcome to ideas on what to try in Python, though.

Thanks,
Jim
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
TanuHoque
Esri Regular Contributor
So, Server 10.1 doesn't like vbscript "if" statements in label expressions?

I have just tried it by copy/pasting your vbscript code and it worked fine for me on the server, the layer draws fine with all features labeled with "NO".

I have also tried with isnull() as a condition to an if..else statement that worked fine as well.... here is the script:
Function FindLabel ([DateST])   FindLabel = "y"   If (isnull([DateST])) Then     FindLabel = "n"   End If End Function


Please open an incident with Esri Tech Support.

In the mean time, can you try creating two different "label classes" where each label-class will have separate SQL queries - one for all features with NULL value, another for all features with non-null value -- no if..else... business in vbscript?

Thanks.
Tanu

View solution in original post

0 Kudos
5 Replies
TanuHoque
Esri Regular Contributor
Jim,
I've just tried it and I didn't see the issue that you have encountered. Map service simply doesn't label those features with <null> value in date field. The vbscript expression I used for labeling is just the field name (please see all attached screen shots).

I have also tried with both FileGDB and SDE (running on SQL Server) and it is the same result - feature draws fine, labeling engine simply don't label features with <null> value.

Here are my recommendations:
1. please contact Tech Support to have them take a look at this.
2. In the meantime, try this: in ArcMap, open the layer properties >> switch to "Label" tab >> choose "Define classes for features and label each class differently" from the "Method" dropdown box >> click on "SQL Query..." button >> set a query to exclude features with <null> value from being labelled >> click OK

Thanks.
Tanu
0 Kudos
JamesCueno
New Contributor II
Okay, except the label isn't just the field value.  Does your label expression use an "if" to evaluate that the field value is not NULL before doing anything else? 

Try this for your label expression:

Function FindLabel (  [AnnexDate]  )
lbl=""

if [AnnexDate] <> "" then
  lbl= lbl&"Annex. Date: "&[AnnexDate]
end if

FindLabel = lbl
End Function
0 Kudos
JamesCueno
New Contributor II
Well, this just got more interesting.  After ruminating on the problem over lunch, I tried simplifying the expression to:

Function FindLabel (  [AnnexDate]  )
lbl="YES"

if 1<>2 then
  lbl = "NO"
end if

FindLabel = lbl
End Function

And that doesn't work either.  So, Server 10.1 doesn't like vbscript "if" statements in label expressions?

Somebody, please, prove me wrong.

It lets me do it in ArcMap and doesn't bothering to let me know when I analyze the project before publishing it, that it might not work.  All of things analyze complains about...
0 Kudos
TanuHoque
Esri Regular Contributor
So, Server 10.1 doesn't like vbscript "if" statements in label expressions?

I have just tried it by copy/pasting your vbscript code and it worked fine for me on the server, the layer draws fine with all features labeled with "NO".

I have also tried with isnull() as a condition to an if..else statement that worked fine as well.... here is the script:
Function FindLabel ([DateST])   FindLabel = "y"   If (isnull([DateST])) Then     FindLabel = "n"   End If End Function


Please open an incident with Esri Tech Support.

In the mean time, can you try creating two different "label classes" where each label-class will have separate SQL queries - one for all features with NULL value, another for all features with non-null value -- no if..else... business in vbscript?

Thanks.
Tanu

View solution in original post

0 Kudos
JamesCueno
New Contributor II
I don't know what's magically changed... but it works now.

At first I thought it was white-space formatting, because I went in and cleaned-up the code.  Made it look pretty (and dropped out the calculation on the area field) and everything worked.  So, I tried breaking the code by ruining the formatting.  Still works.  I pasted in the "if 1<>32" code from yesterday and now that works, too.

Whatever.  It works.

Thanks for the eyeballs.
0 Kudos