Maximo provides a facility whereby unlimited text may be associated with an attribute. This text…
Let’s start with defining some terms. The three biggest terms to define are MboSet, Mbo, and MboValueData. First, the acronym MBO stands for Maximo Business Object. This represents a generic record of data within Maximo. An MBO could be a Work Order, an Asset, an Item, or any of the other hundreds of record types in Maximo.
If we think of a spreadsheet of data, an MboSet would be a tab with columns and many rows of data. The data can be sorted or filtered in many ways. Again, this data could represent any record type in Maximo. An Mbo would be a single row of data represented within an MboSet. Finally, an MboValueData record would be a single cell in the spreadsheet that represents a column of data for a single row.
These terms are used in generic fashion because they have behaviors that can apply to any set of records in Maximo. For example, a set of Work Orders, Assets, Items, etc. can all be filtered, sorted, saved, and looped over in the same fashion. In fact, all record types follow a wide set of general behavior patterns. If you understand these patterns, you’re going to write much better automation scripts in Maximo.
This article will focus on the MboSet collection.
There are three ways to get a handle on an MboSet:
- Use the getThisMboSet() method on an Mbo. Most automation scripts will create an implicit variable at runtime of the script called
mbo. This represents the record on which the script is operating. To get a handle back to the list that the current record is part of you can use some code that looks like this:
mboSet = mbo.getThisMboSet()
This is analogous to going back to the List tab in Maximo.
- Use the getMboSet() method on an Mbo. You can either get an MboSet of data related to the current record, as in a one-to-many relationship, or you can get an MboSet of unrelated data to the current record.
mboSet = mbo.getMboSet("ASSET")
mboSet = mbo.getMboSet("$WOAPPR", "WORKORDER", "status = 'APPR' and siteid = 'BEDFORD'")
- Use the MXServer.getMXServer.getMboSet() method. If you have an existing Mbo in your code, it’s recommended that you use one of the first two options above. However, there are some automation script launch points that won’t contain the implicit
mbovariable (such as Cron Task scripts, some of the Integration scripts, etc.). If that’s the case, then this is your option. You’ll need a
userInfovariable defined to make this connection as a given user.
mboSet = MXServer.getMXServer().getMboSet("WORKORDER", userInfo)
Most objects in the Business Components are collections of objects or the actual objects themselves. When the getMboSet() method is called, a set of objects is returned. When the set is first initialized it has zero members, but it can potentially be filled with all objects that have been saved in the database, depending on which methods are called to restrict the set.
For example, the code:
woSet = mbo.getMboSet("$WOAPPR", "WORKORDER", "status = 'APPR' and siteid = 'BEDFORD'")
returns a collection of WO objects (which represent approved work orders for the BEDFORD site). So far, the set has zero members, but after the following code executes:
wo = woSet.moveFirst()
the set contains all approved work orders in the BEDFORD site (or, more precisely, WO objects representing all approved work orders in the BEDFORD site). The methods moveNext() and moveLast() produce similar results (see below).
Note that the method also returns a remote reference to the object that has become the current member of the collection, in this case the first one. This holds true for the other methods that traverse collections as well (moveNext(), movePrev(), and moveLast()).
A set has a current member pointer that is maintained on the server. The current index of that pointer may be retrieved with the following:
woPos = woSet.getCurrentPosition()
The method returns -1 if there is no current member. Note that the first object in the collection is stored in the zeroth position.
The action of
moveFirst() sets the current member pointer to the first position. The
moveNext() method produces the identical result: the pointer is advanced one position. In the case of
moveLast(), the pointer is set to the last position and all records in the collection are retrieved. This can be very expensive in performance terms and is generally not recommended.
If the current object itself is required, call the following:
wo = woSet.getMbo()
The method returns null if there is no current member. The
getMbo() method can also return the object at an arbitrary position in the set; in this case the desired position is passed as an integer argument. The following code returns the first object in the collection.
wo = woSet.getMbo(0)
The current member pointer is important, as there are many methods in the MboSet class which operate on the current object in the set. Examples of these are
getString(). To change the current member pointer, use methods such as
The contents of the collection can be restricted by using the
setWhere() method. For example:
woSet.setWhere("wonum like '1%'")
This restricts the set to having only members whose work order numbers begin with the character “1”. This method must be called when the set is newly initialized, i.e. before any members have been placed in the set. If the set already has members, call the method:
This clears the current contents of the collection and generates a query to the database. Any modifications or additions made to the set are lost if they are not saved before
reset() is called. The
reset() methods can be called in either order.
setWhere() method is used, it must be passed a valid SQL where clause for the database platform the server is connected to.
Here’s an example of looping over an MboSet:
woSet = mbo.getThisMboSet() wo = woSet.moveFirst() while wo: #Do some things with the work order wo = woSet.moveNext()
For a complete description of all methods available, refer to the MboSet JavaDocs on the IBM Asset Management Developer Center.
Our next article will focus on reading single attributes from the current record in an MboSet.