cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle null or empty element

Sahil
Contributor

Hi,
I need to use null and empty condition in router. curretnly i am using:-
$ZSDATA.IDOC.EDL2.EDL4.BEL != “”
but i feel i am not handling it correctly.
Any inputs?

4 REPLIES 4

j_angelevski
Contributor III

Hi @Sahil ,

Which value are you expecting to be null ? With your current condition it will only check if …BEL is not empty and if any value before it is null it will fail.

You can either try this with the .get() method. You can also try with Data Validator snap to check if a value is not present or if it is empty.

clinton_hemmant
New Contributor III

Data Validator does not seem to be able to check null values

Must use minLength and Constraint value = 1

Required does not work for null.  Pattern = null does not work

endor_force
New Contributor III

Null values should be possible to identify in expressions in most places.

The following condition would check that BEL is not blank or null, split them up if you need to handle them separately in the router. 

$ZSDATA.IDOC.EDL2.EDL4.BEL != "" && $ZSDATA.IDOC.EDL2.EDL4.BEL != null

If you need to do the opposite to catch if an element is null or blank you simply change the conditions:

$ZSDATA.IDOC.EDL2.EDL4.BEL == "" || $ZSDATA.IDOC.EDL2.EDL4.BEL == null


If you have scenarios where you can be missing the element completely you may have to also throw in a check first that the object exists at all.
If you are having null safe access in a mapper where you map BEL, it would make this redundant.

$ZSDATA.IDOC.EDL2.EDL4.hasPath("BEL")