In our previous posts 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 update single attributes on an Mbo, or in our spreadsheet analogy, update data within a single cell within a row.
If there is a need to add a new object to a collection, the
add() method may be on an MboSet, as in the following example:
newWo = woSet.add()
This returns a reference to the newly added object and sets the current index in the collection to point to it. The location of the new object within the collection is not guaranteed, so no assumptions should be made as to where it has been placed relative to the previous current index. You can use the
getString() method to fetch default or autokey values for particular attributes. One of the best examples of an autokey value is the “wonum” attribute, which must be unique as the principal identifier of a work order. These values are set automatically by Maximo as part of the
Once a new object has been created, the attributes of the object can be altered by using the
setValue() method. This method call can be performed directly on the newly added object:
As mentioned previously, changing an attribute value may result in other attribute values being updated.
Once all values have been set, the
save() method should then be called:
save() method may throw an exception, as was discussed in the section on modifying objects. The most common exception thrown by the saving of a newly added object results from a required attribute not being set. The exception returned in this case is of type MXApplicationException with an error group and key of “system” and “null”, respectively.
Our next article will focus on exception handling with Mbos and MboSets.