MBOs in Automation Scripts: Reading Single Attributes of an MboSet
In our last post in this series, we talked about how an MboSet is a collection of Mbo objects. This is analogous to a spreadsheet of data representing an MboSet, and a single row within that spreadsheet representing an Mbo. This article will discuss how to read single attributes from an Mbo, or in our spreadsheet analogy, look at data within a single cell within a row. Once an MboSet has been fetched, data associated with the individual objects it contains can be extracted. Attributes that are associated with character data types, such as ALN, UPPER, and LOWER, can be retrieved by using the getString() method. The getString() method is a member of both the Mbo and MboSet classes. The Mbo version fetches data from the Mbo object itself; the MboSet version fetches data from the current member of the MboSet. For example, here moveFirst() is called to set the current member pointer to the first object in the woSet collection. Since woSet was newly restricted from a new setWhere() call, moveFirst() also triggers the retrieval of the record from the server. The getString() method of the woSet object is called and the value of the description attribute of the current member is retrieved.
In the next example the moveFirst() call, in addition to the above functions, also returns the work order object which is the new current member of woSet. The getString() method is called through the object wo and the value of the description attribute is retrieved.
woSet = mbo.getThisMboSet() woSet.setWhere("wonum='1100'") woSet.moveFirst() woDesc = woSet.getString("DESCRIPTION")
Next, moveFirst() is called to make the first object the current member. A reference to that member is then retrieved by a getMbo() call. The getString() method is then called as before.
woSet = mbo.getThisMboSet() woSet.setWhere("wonum='1100'") wo = woSet.moveFirst() woDesc = wo.getString("DESCRIPTION")
Note that the result is the same in each of these three examples. Which combination of calls should be used to reach the result depends entirely on what is most convenient in a given situation. The getString() method may be used on all attributes regardless of their data types. There are also getDate(), getInt(), getLong(), getByte(), getBoolean(), getFloat() and getDouble() methods, which return the value of an attribute as something other than a string. An attempt to use these methods on an underlying attribute not of the correct type results in an exception being thrown. For example the following does not work because the attribute is not of type DATE or DATETIME.
woSet = mbo.getThisMboSet() woSet.setWhere("wonum='1100'") woSet.moveFirst() wo = woSet.getMbo() woDesc = wo.getString("DESCRIPTION")
A list of the attributes whose values may be retrieved and the objects to which they belong is listed in the MAXATTRIBUTE table in the Maximo database. The OBJECTNAME column of this table corresponds to the table name, while the ATTRIBUTENAME column corresponds to the column name. For a complete description of all methods available, refer to the Mbo and MboSet JavaDocs on the IBM Asset Management Developer Center. Our next article will focus on reading multiple attributes from the current record in an MboSet.
woDate = woSet.getDate("DESCRIPTION")
Preventing fields from Editing Once Record is in Workflow I like this problem because it involves a few...
How to enable the print button in Maximo. By default, Maximo only allows the MAXADMIN group to have...