AnsweredAssumed Answered

ArcGIS Maplex Python Labeling: If a value in a date field is null, how do I still show other values?

Question asked by michaelhutchison on Mar 9, 2017
Latest reply on Mar 13, 2017 by Dan_Patterson

I'm trying to label point features with ArcGIS Maplex Engine, using [field1], [field2], [field3], [datefield].  My code is set up to label [field1] + '\n' + [datefield][-2:].  If [field1] is null, it'll label [field2] + '\n' + [field3] + '\n' + [datefield][-2:].  For whatever reason, my code doesn't work if a feature has a null value in [datefield].  How do I tell my code if the [datefield] is null, label [field1] AND if [datefield] and [field1] is null, label [field2] + '\n' + [field3]?  This is my code so far.

 

def FindLabel ( [field1], [field2], [field3], [datefield] ):
  if str([field1]) == "None" :
    return [field2] + '\n' + [field3] + '\n' + [datefield][-2:]
  elif str([field1]) != "None" :
    return [field1] + '\n' + [datefield][-2:]

 

I tried adding this section but the engine doesn't seem to read it.

 

  elif [datefield] == "None" :

    return [field1]

  elif [datefield] == "None" and str([field1]) == "None" :

    return [field2] + '\n' + [field3]

 

My entire code is this.

 

def FindLabel ( [field1], [field2], [field3], [datefield] ):
  if str([field1]) == "None" :
    return [field2] + '\n' + [field3] + '\n' + [datefield][-2:]
  elif str([field1]) != "None" :
    return [field1] + '\n' + [datefield][-2:]

  elif [datefield] == "None" :

    return [field1]

  elif [datefield] == "None" and str([field1]) == "None" :

    return [field2] + '\n' + [field3]

 

Thanks for the help.

Outcomes