Updating End Points and Reloading Cache in Automation Script

In Maximo you can use End Points to point to External APIs to pull in data. You can invoke those End Points in a variety of ways, including inside an Automation Script. Take the following code as an example:

handler = Router.getHandler('ENDPOINTNAME');
responseBytes = handler.invoke(null, null);

You can then parse the response that comes back and use that data in any way that meets your needs. Recently we were working with an external API that required an initial login to capture an API Key to be used with future calls. We called the Login API and then grabbed an API Key from the response object. We then needed to update a different End Point to utilize this API Key as an HTTP Header in future calls.

This appeared to work in Maximo as we would see the data show up on the updated End Point. However, each time we invoked the End Point it would throw an error that it was not able to connect. We would then restart Maximo and everything would start working. What we found is that End Point data in Maximo is cached. After updating an End Point, we needed to reload the End Point cache to make a successful connection. To do that we added a line in the automation script after we updated and saved the End Point with the new API Key. The line that is needed is:

MXServer.getMXServer().reloadMaximoCache(EndPointCache.getInstance().getName(), true);

After running this code we can now successfully call our updated End Point. Be aware that there are several similar objects that are cached when Maximo starts up, such as Relationships, Integration information, some Domain information, etc. If updates are made to those records, you may need to refresh the Maximo cache for those records as well.

Hope this helps!

Calling Automation Scripts in a Federated MBO Endpoint

With the new version of Maximo we are now able to use Federated MBOs. Federated MBOs allow us to show live data from external systems without storing the data in Maximo. In that call you can have a static URL or you can dynamically update the URL to pull different data every time. For instance, if you only want to see the last 24 hours of data in the external system you can update the call to do so. (Note: you would have to have the external data api set up to add parameters to the call in order to do this.) Another option would be updating the call based on the user logged in to show different data for different users.

In order to do this you will first need to update the URL on the End Point to call a custom automation script. You will need to update your URL to be replaced with “script:LAST24HOURS” instead of the hard coded date value. An example URL would be “http://externalsystem?data=script:LAST24HOURS”

Once you have the URL constructed you will need to make an Automation Script called LAST24HOURS. The script will need to look like this:

Note: The value that is passed back to the URL is what you set token to.

Now every time the user goes to see the data and the URL is called and the script will run to pass in the value to only show the last 24 hours.

You can pass in any value that you chose by using the automation script. It does not just have to be a date. It can be a value based on the user that is logged in and making the call.

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.