Reading and updating Mbo's attributes

This entry is part of the Maximo Java Development series.

In this post I have explained how to query and fetch MBOs from the database. In this small article I will show how to get and set the attributes of an Mbo.


How to read attributes

To read the attributes of an Mbo you can use teh following getXxxx methods:

All these methods accept only one argument which is the name of the attribute to be retrieved from the Mbo.
Here is a a small example showing how to retrieve the ASSETNUM and ASSETID of an asset.

String assetnum = asset.getString("ASSETNUM");
int assetid = asset.getInt("ASSETID");

The is also a special technique to retrieve multiple attributes using the getMboValueData method as described in this post.

How to set attributes

To modify the value of a field you can use setValue methods. The setValueNull method can be used to set a null value. Here is a a small example showing how to set the DESCRIPTION and INSTALLDATE of an asset.

asset.setValue("DESCRIPTION", "New description");
asset.setValue("INSTALLDATE", new Date());

All setValue methods have a second version that accepts some flags. The valid flags are defined in the MboConstants class. Here are the most important ones:

They can be merged with the bitwise OR operator '|'.

asset.setValue("DESCRIPTION", "d1", NOVALIDATION);
asset.setValue("DESCRIPTION", "d1", NOVALIDATION | NOACCESSCHECK);


Labels: , ,