MBOs in Automation Scripts: Adding New Objects to the Collection
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:
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
newWo = woSet.add()
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
add()method. 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.
As an IBM Maximo mobile solution provider, A3J Group consistently improves the functionality and features...
Pretend you are going to take a real vacation, two weeks in Spain with no work laptop. You have planned...
A3J Group is happy to announce the latest MxMobile releases below. The releases will be available on...
Hi Alex.. can you please help me in writing a script on attribute launch point for the below requirement?
In asset templates application, when user adds a master pm to it, an attribute(x) in asset template application and an attribute(y) in jobplan that’s attached to master pm that user added in asset templates application has to match. If it doesn’t match, error should be displayed.
ATTRIBUTE in PLUSCTEMPLATE and ATTRIBUTE in JOBPLAN should be compared. Please help!
Hi Alex. I am trying to copy the values from existing table in maximo to new one one that is created by me. So when the status changes in work order the values of child object in workorder app will be copied to new table. The structure of tables are the sames i mean the same attributes. First i try to copy just one value but it doesnt copy. And there is no error showed up.
from psdi.server import MXServer
from psdi.mbo import Mbo
from psdi.mbo import MboConstants
from psdi.util.logging import MXLoggerFactory
logger = MXLoggerFactory.getLogger(“maximo.script”)
status = mbo.getString(“STATUS”)
if status in (“AVVIATO”):
for i in range (0, sourceItemSet.count()):
if targetItemSet is not None:
logger.info(“COMPY VALUES” + ” – ” + wonum )
newMbo.setValue(“WONUM”,wonum,MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION)
Aynura Mahmudova – did you save your new set?