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:

  • getBoolean
  • getByte
  • getBytes
  • getDate
  • getDouble
  • getFloat
  • getInt
  • getLong
  • getString

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:

  • NOVALIDATION: suppress validation
  • NOACTION: suppress action
  • NOVALIDATION_AND_NOACTION: suppress validation and action
  • NOACCESSCHECK: suppress access control checks

They can be merged with the bitwise OR operator ‘|’.

asset.setValue("DESCRIPTION", "d1", NOVALIDATION);
asset.setValue("DESCRIPTION", "d1", NOVALIDATION | NOACCESSCHECK);
Reading and updating Mbo’s attributes

4 thoughts on “Reading and updating Mbo’s attributes

  1. Is there anything special to setting attribute values when the attribute type is a TABLEVALUE.
    For instance, to set an attribute that uses the People table, and the attribute specified for the attribute is DISPLAYNAME, can you just add a valid string for a DISPLAYNAME?

  2. hi Bruno in this article your title is Reading and updating Mbo's attributes but ı think you explained Reading and setting Mbo's attributes
    ı mean how can I update one record or can I? for example MboSetRemote assetMboSet = session.getMboSet("ASSET");
    assetMboSet.setOrderBy("ASSETNUM");
    assetMboSet.setWhere("LOCATION='BEDFORD'");

    MboRemote assetMbo;
    for(int j=0; ((assetMbo = assetMboSet.getMbo(j)) != null); j++)
    {
    assetMbo.setValue("DESCRIPTION", "New description");

    }
    Can I?

  3. Hi Bruno,
    I am trying to setValue for an attribute which is an ID of another object. This does not work. How can I set the value of an attribute which stores the foreign key of a related object?

  4. Hello Bruno,

    I’m trying to get what mbo’s attribute is marked as required, and I can’t see a clear clue how to have it. I’ve tried using methods from entities classes (e.g. ERMEntity tree), but they returned null value.

    Any thought will be welcome.
    Thanks for reading.

    Regards

Leave a Reply

Your email address will not be published.


Scroll to top