How to check for null values

This entry is part of the Maximo Java Development series.

A very common doubt when extending MBOs is what value returns the Mbo.getString() method when the target field has a null value. The answer is: It returns an empty string "".
Thus to check if the DESCRIPTION of an Mbo is empty or null you can use two basic approaches.
getString("DESCRIPTION").equals("")
or
getString("DESCRIPTION").length()==0

If you need do distinguish between null values and empty string you can use the Mbo.getMboValueData() method.
Thus to check if the DESCRIPTION of an Mbo is null use this code snippet.
getMboValueData("DESCRIPTION").isNull()

If you are in an Mbo class you can perform the same check as follows:
isNull("DESCRIPTION")


Labels: , ,