Oracle database treats empty strings as nulls while IBM DB2 and SQL Server treats empty strings as strings of zero length, not NULLs.
Maximo businessobjects persistence layer always treats empty strings as nulls in order to have a common behavior across different database servers.
The getString function will always returns an empty string if the underlying filed value is an empty string or null. You must use the mbo.isNull method to understand if a string is null (or empty).
For this reason, I always use the following syntax for checking null/empty strings:
if mbo.getString("DESCRIPTION") != "":
mbo.setValue("DESCRIPTION", mbo.getString("CLASSIFICATIONID"))
The following piece of code is exactly equivalent to the above one:
if mbo.isNull("DESCRIPTION"):
mbo.setValue("DESCRIPTION", mbo.getString("CLASSIFICATIONID"))
------------------------------
Bruno Portaluri
Maximo Principal Consultant
OMNINECS Europe
Rome
+393355784962
------------------------------
Original Message:
Sent: Tue November 09, 2021 04:34 PM
From: User1971
Subject: Clean Jython: If field is null
MAM 7.6.1.2, Jython, Oracle 19c:
I have a Jython automation script that checks to see if CLASSSTRUCTURE.DESCRIPTION is null:
if not mbo.getString("DESCRIPTION"):
mbo.setValue("DESCRIPTION", mbo.getString("CLASSIFICATIONID"))
As a novice, I find if not mbo.getString("DESCRIPTION"): to be unintuitive to read.
I'd rather use something like if mbo.isNull("DESCRIPTION"): . I find that easier to read.
Question:
What is a good/intuitive way to check for nulls via Jython? Do I need to worry about empty strings?
My best guess is that Python variables can have empty strings (''), but Oracle VARCHAR2 columns can't have empty strings ('' is automatically converted to null).
[edited for clarity]
Details:
As mentioned, I don't think it's possible to store an empty string like '' (no space) in VARCHAR2 columns in Oracle tables (the Maximo db uses the VARCHAR2 datatype for text). Oracle automatically converts '' to null when inserting data into a table.
As an example, I mocked up some sample data in a online database testing website called "db<>fiddle":
https://dbfiddle.uk/?rdbms=oracle_18&fiddle=e6fda0c32c59e027da6015c838b49f7a
If I understand correctly, the test confirms that Oracle automatically converts '' to null when inserting data into a VARCHAR2 column.

#Maximo
#AssetandFacilitiesManagement