IBM introduced Automation Scripts in Maximo 7.5 as a way to inject scripting code into key system events in order to alleviate the need for Java customization to the product. Launch Points for object-based events, attribute-based events, and action-based events were created to trigger these scripts to run. This gave developers the ability to trigger scripting code within Maximo to fire in the place of the most common methods that custom Java code had been used for previously.

As the usage of Automation Scripts has grown over the years, IBM has expanded its Launch Points to include additional events such as various points in the Integration cycle to again alleviate the need to write custom Java code.

One commonly used method that has been seemingly overlooked is the add() method in the base Mbo class. This method fires immediately upon creation of a new record in Maximo. There is an option in object-based Launch Points to fire only on the add event, however, that triggers only upon the save event of newly created records – not immediately after a new record is created.

In one of the later releases of Maximo 7.6, IBM added an undocumented hook into their code that allows developers to fire an Automation Script upon creation of a new record. This article will walk you through how to do this.

The Mbo.add() method is typically used for:

  1. Conditionally defaulting values on a child record based on information from the parent record
  2. Defaulting values on a custom child record from a parent record, such as its primary key values

Creating a Script to Fire on Add

To have your Automation Script run immediately upon creation of a new record, you can utilize a little known trick. The script itself will not contain any Launch Points, however, there is code within Maximo that will look for an active script with the name OBJECTNAME.NEW and run it, if it finds a match. When using this feature, replace OBJECTNAME with the name of the record type, such as ASSET or WORKORDER.

Let’s look at an example. Say that your users have a requirement to default the Line Type of a PO Line to different values based upon the PO Type that has been selected. Specifically, if the PO Type is SERV, then the Line Type of a PO Line should default to SERVICE. Otherwise, it should default to ITEM. Here are the steps to achieve this:

  1. Log into Maximo as an administrative user
  2. Navigate to the System Configuration > Platform Configuration > Automation Scripts application
  3. From the More Actions or Select Action menu, choose Create > Script option
    1. Script: POLINE.NEW (this is the trick! Make sure that the name is formatted properly)
    2. Description: Default the PO Line Type based off the PO Type
    3. Script Language: python
    4. Log Level: ERROR
    5. Active: Yes
    6. Source Code: [see below]
  4. Click the Create button
po = mbo.getOwner()
if po and po.isBasedOn("PO"):
    poType = po.getString("POTYPE")
    if poType == "SERV":
        mbo.setValue("LINETYPE", "SERVICE")

Once you have created the script, you will be able to go to the PO application and test it out. Create a new PO with a type of SERV (Service). Next, navigate to the PO Lines tab and select New Row. You will see the Line Type for that row is Service. Create another PO record with the type STD (Standard), then select New Row on the PO Lines tab for that PO and you will see the Line Type is Item.

Another Example

Let’s say your users would like to start capturing change history against the STATUS field on Assets, as other similar objects do. After adding a new database object called ASSETSTATUSHIST, you can create a new Automation Script to populate the fields in that table from the parent Asset record.

  1. Log into Maximo as an administrative user
  2. Navigate to the System Configuration > Platform Configuration > Automation Scripts application
  3. From the More Actions or Select Action menu, choose Create > Script option
    1. Script: ASSETSTATUSHIST.NEW
    2. Description: Populate the fields on a new Asset Status History record from the Asset
    3. Script Language: python
    4. Log Level: ERROR
    5. Active: Yes
    6. Source Code: [see below]
  4. Click the Create button
asset = mbo.getOwner()
if asset and asset.isBasedOn("ASSET"):
    mbo.setValue("ASSETNUM", asset.getString("ASSETNUM"), mbo.NOACCESSCHECK)
    mbo.setValue("STATUS", asset.getString("STATUS"), mbo.NOACCESSCHECK)
    mbo.setValue("CHANGEDATE", asset.getDate("STATUSDATE"), mbo.NOACCESSCHECK)
    mbo.setValue("CHANGEBY", asset.getString("CHANGEBY"), mbo.NOACCESSCHECK)

When you add a new row to the ASSETSTATUSHIST table, it will automatically populate with the above values based off of the parent Asset record.

That’s it for now! Please feel free to leave any comments or questions below. For visual instruction of the previous steps, check out our video tutorial.