
MBOs in Automation Scripts: Update Attributes of an Mbo
- July 25, 2019
- Alex
- 5 Responses
- July 25, 2019
- Alex
- 5 Responses
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.
To modify an object in the collection, the object must first be found. Most of the time, the launch points in automation scripts will supply an implicit variable called mbo that refers to the current record. Alternatively, you can get a handle to an Mbo from an MboSet as described in previous articles of this series – remember the
setWhere()
and moveFirst()
methods. Once you have an Mbo, changes are made using the setValue()
method. As is the case with other methods, setValue()
is a member of both the Mbo and MboSet classes.
Our first example changes the description of the current Mbo (a work order) by calling the mbo variable’s version of the setValue() method.
mbo.setValue("DESCRIPTION", "Changed the description")
In the setValue()
method, passing the second argument as a string works for all attributes, regardless of their underlying data types. For example, if an attribute is a numeric type, passing the string “1” is allowed. There are also setValue() method calls that take the long, int, Date, boolean, float, or double data types as the second argument.
This call will throw an exception if the underlying data type does not match the type of the value passed in the call. For example the following code does not work.
mbo.setValue("description", 1.0)
A call to set the value of a particular attribute may result in the values of other attributes changing. For example, setting the “assetnum” attribute of a work order may result in the “location” attribute being updated as well. To check the new value, getString() could be used on the “location” attribute.
Once all values have been modified, the save() method can then be called.
mbo.getThisMboSet().save()
This saves and commits all changes to the database. In most cases, an explicit call to save()
is not necessary. In cases where the automation script fires before the save event, the save event will trigger automatically after the execution of the script.
If there is an error during the save, an exception is thrown and the changes are not saved. In that case, the collection is left in exactly the same state as prior to the save() call. This allows appropriate action to be taken and the save() call to be resubmitted.
There is a third argument that can be passed to the setValue()
method, which is the Access Modifier. This should only be used when you are certain of the implications of using it. In essence, standard application logic can be bypassed by using access modifiers, which is why they should be used only when necessary. Standard access modifiers are:
- NOACCESSCHECK: Suppresses the “Field is Read Only” message and performs the update regardless of whether the field is editable or not.
- NOVALIDATION: Update the field without validating the data being entered.
- NOACTION: Do not perform related system actions when updating. For example, do not update the location on a work order when updating the asset.
mbo.setValue("DESCRIPTION", "Update a read only field", mbo.NOACCESSCHECK)
To update a field and not perform the validation and action events:
mbo.setValue("DESCRIPTION", "Update a field without validation or action", mbo.NOVALIDATION|mbo.NOACTION)
Putting all three together:
mbo.setValue("DESCRIPTION", "Please be careful doing this", mbo.NOACCESSCHECK|mbo.NOVALIDATION|mbo.NOACTION)
A list of attributes whose values may be modified and the objects to which they belong can be found in the MAXATTRIBUTE table in the MAXIMO database. The OBJECTNAME column of this table corresponds to the object name. The ATTRIBUTENAME column corresponds to the attribute name.
Our next article will focus on how to add new Mbo records into an MboSet. Share This
Alex
Related Posts

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...
No posts found
5 Comments
This was very informative and awesome. Thank you, Alex.
Does capitalization matter with the keys for Mbo? Would mbo.setValue(“ACCESS_KEY”, “5^*^%$TRUE”); change the same cell as mbo.setValue(“AccessKey, “5^*^%$TRUE”);
Why does this happen?
A call to set the value of a particular attribute may result in the values of other attributes changing. For example, setting the “assetnum” attribute of a work order may result in the “location” attribute being updated as well. To check the new value, getString() could be used on the “location” attribute.
In most cases, an explicit call to save() is not necessary.
What makes it a case where it is necessary?
No problem, thanks for the questions!
Hope this helps!
Hi Alex.
I wrote this script to copy the value from existing table in maximo to my new table. The tables are the same i mean same attributes. So when the status changes it should pass from old table to the new one.
First i try to add just work order number but it doesnt copy the values and it doesnt give any error.
#Add records in Z0PLANNEDCOST table when the new work order added to the workflow.
#Statutes are WAPPR, ASSEGNATO, COMP, ASSEGNATOWF, AVVIATO
#Attribute Launch Point: STATUS
from psdi.server import MXServer
from psdi.mbo import Mbo
from psdi.mbo import MboConstants
from psdi.mbo import MboRemote
from psdi.mbo import MboSetRemote
import sys
from psdi.util.logging import MXLoggerFactory
logger = MXLoggerFactory.getLogger(“maximo.script”)
sourceItemSet= mbo.getMboSet(“SHOWPLANITEM”)
#sourceItemSetSelection=sourceItemSet.getSelection()
targetItemSet= mbo.getMboSet(“PLANNEDZ0WPITEM”)
status = mbo.getString(“STATUS”)
#i=0
if status in (“AVVIATO”):
for i in range (0, sourceItemSet.count()):
if targetItemSet is not None:
newMbo=targetItemSet.add()
wonum =sourceItemSet.getMbo(i).getString(“WONUM”)
logger.info(“COMPY VALUES” + ” – ” + wonum )
newMbo.setValue(“WONUM”,wonum,MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION)
Hi I’m writing a script automation with object launch point and it’s raises error message “indefined mbo variable” on this line mbo.SetFieldFlag(“quantity”,MboConstants.READONLY,false). I don’t understand this error because it’s supposed that mbo is an explicit variable.
Thanks and regards
Pablo
If you’re using an Object launch point, then you should have mbo as an implicit variable to the script. To make a field read-only, you’ll probably want to use the initialize value event that’s part of the Object launch point.
As for the code, since the Mbo class implements MboConstants you can write your script like this. Please note this is python syntax:
mbo.setFieldFlag("quantity", mbo.READONLY, False)
Hope this helps,
Alex