
MBOs in Automation Scripts: Reading Single Attributes of an MboSet
- May 16, 2019
- Alex
- 5 Responses
- May 16, 2019
- Alex
- 5 Responses
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.
woSet = mbo.getThisMboSet()
woSet.setWhere("wonum='1100'")
woSet.moveFirst()
woDesc = woSet.getString("DESCRIPTION")
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'")
wo = woSet.moveFirst()
woDesc = wo.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'")
woSet.moveFirst()
wo = woSet.getMbo()
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.
woDate = woSet.getDate("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.
5 Comments
can you update relationships also? let say i have my main object on the screen and another table below it that is coming from a relationship. I cant seem to fetch the data I imputed on screen.
Yes, you can use relationships as well. In a 1:1 relationship you can use the “dot” notation (e.g. ASSET.DESCRIPTION). In a 1:many relationship you can use the mbo.getMboSet(RELATIONSHIP) to get a list of related records. Make sure that you’re using the same relationship name as defined in the UI presentation, and make sure that you’re populating the key attributes by default on the new record that make up the relationship.
We’ll have a subsequent article dedicated to object relationships as part of this blog series.
Hi Alex,
Can we use “OR” condition between two required field to update relationships?
As an example for PRline Object for an Item num model or catalog num is required.
Is it possible to do?
Please let me know.
Thanks
Tanzina
Best way to do this is to create an automation script with an object save launch point, like PRLINE.SAVE. In your script you can check to see if both of those fields are populated via mbo.isNull(‘ITEMNUM’) and mbo.isNull(‘CATALOGCODE’). If both are empty then throw an exception to the user.
Thanks For your response.