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);
Source:http://maximodev.blogspot.com/2012/11/reading-and-updating-mbos-attributes.html
Tidak ada komentar:
Posting Komentar