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:

  1. NOACCESSCHECK: Suppresses the “Field is Read Only” message and performs the update regardless of whether the field is editable or not.
  2. NOVALIDATION: Update the field without validating the data being entered.
  3. NOACTION: Do not perform related system actions when updating. For example, do not update the location on a work order when updating the asset.

These access modifiers can be used on an update by themselves or combined together. For example, to update a field even though Maximo has the field marked as read only:

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.

Alex Walter is the Chief Innovation Officer at the A3J Group, a company he formed to address the need for innovative software solutions and integrated consulting services within the EAM industry. Alex brings 17 plus years of experience in business consulting in various industries including Life Sciences, Oil and Gas, Water and Waste Management, Education, Government Facilities, among others. Alex lives in Tampa, FL with his wife, two sons, and dogs. In his free time, he enjoys running half marathons, making space in his garage for new camping and outdoor equipment, traveling to far off places with the Walter Circus, and remaining hopeful that his NY Jets' best days are ahead of them and not behind.

2 Thoughts on “MBOs in Automation Scripts: Update Attributes of an Mbo”

  • 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!

      1. Capitalization does not matter. Maximo will locate the correct attribute to update regardless of the case you use to identify it.
      2. Business rules in Maximo may apply to certain fields. The location of a work order is updated automatically when an asset is updated because the asset resides in a certain location. If the location is empty and an asset is chosen, you would want the location to default to that of the asset you selected. This is a simple case, but it extends throughout the Maximo application.
      3. The call to save() is not necessary if you update an MboSet that is related to the current Mbo. This is because the save() will automatically fire on the current record, and any related MboSet’s will also be saved. If you get an independent MboSet from the MXServer (see examples from the first article in this series) you will need to explicitly save.

      Hope this helps!

Leave a Reply

Your email address will not be published.