Skip to content

Launch Automation Script on New Record Creation in Maximo

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.

Share This

Related Posts

ibm_mxmobile_maximo mobile_app_application_suite_report_maintenance_reliability_industry_4_work_order_enterprise_asset_management_inventory_perform_count_log_time_create_meter_reading_shipping_and_recieving_mobility_admin_service_request_issue_parts_material_approve_task_job_plan_software_upgrade
MxMobile Update May 2023 Release
As an IBM Maximo mobile solution provider, A3J Group consistently improves the functionality and features...
integration-trobleshooting-IBM-Maximo-A3J-Group-Consulting-e1636065766665
Workflow Delegates
Pretend you are going to take a real vacation, two weeks in Spain with no work laptop. You have planned...
ibm_mxmobile_maximo mobile_app_application_suite_report_maintenance_reliability_industry_4_work_order_enterprise_asset_management_inventory_perform_count_log_time_create_meter_reading_shipping_and_recieving_mobility_admin_service_request_issue_parts_material_approve_task_job_plan_software_upgrade
MxMobile Update April 2023 Release
A3J Group is happy to announce the latest MxMobile releases below. The releases will be available on...

2 Responses

2 Comments

  1. Hi Guys, I am having a problem with one of my script which is not firing in the following scenario.
    1. On Inventory Usage app, usage type = Transfer, Pick “From Storeroom” field as some value. On Inventory Usage line, : I have written an attribute launch point on “GL Debit Account: field event is Validate. When we pick up value for field “To Storeroom”: then MX populates GL Debit Account field value. Then my script fires and does some validation. Works fine.

    Problem is when User selects Item first and then “To Storeroom” field then my script doesn’t fire even though MX populates GL Debit Account field value.

    Any idea?

    I don’t want to write any Java Code. I also don’t want to go with Domain since OOB there are Field level java class on those fields which is dynamically controlling the associated value list. I don’t wann mess with that code.

  2. Hi Alex,

    Great article! I was able to use this to generate custom autokey for Po’s (Prefix-User Division-Seed). However the script does not fire when duplicating the PO’s.

    I tried creating a script called PO.DUPLICATE and have a similar code in there, but it still doesn’t work. Any insights? I would appreciate your help!

    from java.util import Date
    from psdi.server import MXServer
    from psdi.mbo import SqlFormat

    previousRevisionSet = mbo.getPreviousRevision()

    if (previousRevisionSet is not None):

    mxserver = MXServer.getMXServer()

    current_user= mxserver.getUserInfo(user)
    current_personid = current_user.getPersonId()

    personSet = mxserver.getMboSet(“PERSON”,mbo.getUserInfo())
    personSet.setWhere(“PERSONID='”+current_personid+”‘”)
    personSet.reset()
    person = personSet.getMbo(0)
    div = person.getString(“DEPARTMENT”)

    mbo.setValue(“PO1”, div)
    autoKeySet = mxserver.getMboSet(“AUTOKEY”,mbo.getUserInfo())

    if((div ==’193′ or div==’195′ or div==’138′ or div==’183′)):
    autoKeySet.setWhere(“AUTOKEYNAME=’PONUM’ and SITEID=’GAITHER’ and ORGID=’NIST'”)
    autoKeySet.reset()
    autoKeyMbo=autoKeySet.getMbo(0)
    prefix= autoKeyMbo.getString(“PREFIX”)
    seed = autoKeyMbo.getInt(“SEED”)
    mbo.setValue(“PONUM”, prefix+div+ “-“+str(seed))

    Thanks,
    Megha


Add a Comment