↓ Skip to main content
An ink and watercolour drawing of a brass balance scale on a workbench. A wooden block sits on the left pan and three brass weights stand on the right pan, with the beam level. Two more brass weights lie on the bench beside the scale.

Testing Automation Scripts

Maximo Automation Scripts - This article is part of a series.
Part 30: This Article
The Automation Scripts application has a test dialog that can run almost every kind of script. Its rules are spread over many pages, and a few of them decide whether a test changes real data. This article collects them, and shows a second way to test that we used for every live check in this series.

We checked IBM’s testing pages against the behaviour of Manage in the MAS 9.2 series. Where the pages and Manage disagree, this page follows Manage.

The Test Script dialog
#

Open the script and choose Test Script. You can pick a launch point; without a choice, the test uses the script’s first one. The dialog prepares a record, runs the script, and shows two results:

  • Data: the record after the test, as JSON when “test with JSON” is on, otherwise as XML.
  • Process Log: the output of service.log and service.logError, of print, and the message of an error. The log_info style methods still go to the log file, as article 14 explains.

The object path
#

The object path tells the test which record to use:

PathRecord
ASSET[assetnum='11430']the first asset that the where clause finds
ASSETa new asset when the launch point adds records; otherwise the first asset in the table
PO[ponum='1056']/POLINEa new line under that purchase order: a part after a slash is a relationship

The launch point decides between new and existing. An event that only adds records makes the test add one. An update or delete event makes it load one. A where clause together with a new record is refused.

The Set Attribute Value table puts values on the record before the run. For the launch point’s own field, the test sets the value twice: first with the event’s own checks switched off, then again with no flag.

What a test changes
#

This part decides whether a test is safe on a system with real data:

  • Save events are rolled back. The test runs the save in a transaction, writes to the database without a commit, and rolls back.
  • After commit is the exception. For an after commit launch point, the test saves the set, and that commits. The data is changed for real.
  • Integration tests are rolled back. Inbound files, invoke channels and the exits run in a transaction that the test rolls back.
  • An action test skips the action’s security check. A test can pass where a real user would be refused.
  • A script that saves for itself still commits. The rollback covers the record’s transaction. A set that the script opens and saves on its own commits, test or no test. Article 15 explains why.

What each script type needs
#

Script typeInput in the dialogNote
Object and attribute eventsan object path, attribute valuesfor can delete, the test calls delete on the record
Attribute init and lookupsan object paththe test reads the field, or asks for its list
OBJECT.NEW and OBJECT.DUPLICATEan object path.NEW forces a new record; .DUPLICATE copies the record
Inbound object structurean XML or JSON fileruns through the structure’s service, rolled back
Outbound object structurean object paththe record is serialized through the structure
Query and action scriptsa where clause, sqp: parametersthe action’s security check is off
Channels and servicesa file, an external systeman enterprise service test needs the external system
Endpoint and REST scriptstype ENDPOINT or RESTAPI, a file or parametersa REST test uses POST unless you choose another method
Conditiona plain where clausethe result is thrown away; log it to see it
Actionan object paththe launch point name is passed as the action
Rolean object path, OBJECT[where]a plain where clause fails
MXERRgroup and key from the nameboth can be changed in the dialog
Formulaone row per parameterthe test evaluates NAME(p0,p1) as a formula
Cron tasktype CRONTASK, an object paththe path arrives as arg

Two of these hide their answer. A condition test runs the script and discards evalresult, so add a service.log line with the result. And a role test reads its path like an object test, so assetnum = '11430' alone fails; write ASSET[assetnum='11430'].

One switch is easy to miss: setup logic of a non-persistent object needs the system property mxe.script.callsetuponinit set to 1. It is a run-time switch, so it also changes behaviour outside tests.

A second way: through the REST script handler
#

The dialog is a screen. For tests that a command line or a pipeline can repeat, we used another way in this series: a test script without a launch point, called through /maximo/api/script/<NAME>. Article 22 shows the handler.

Such a driver script opens a record, hands it to the script under test as a library call, and returns what it sees as JSON:

from java.util import HashMap
from com.ibm.json.java import JSONObject

assets = service.getMboSet("ASSET", userInfo)
try:
    assets.setWhere("assetnum = '11430' and siteid = 'BEDFORD'")
    asset = assets.moveFirst()
    ctx = HashMap()
    ctx.put("mbo", asset)
    service.invokeScript("ASSET_SAVE_SETPRIORITY", ctx)
    result = JSONObject()
    result.put("priority", asset.getString("priority"))
    responseBody = result.serialize()
finally:
    assets.cleanup()

ASSET_SAVE_SETPRIORITY stands for the script under test. The driver never saves, and the clean-up drops every change. The record reaches the script under test through the mbo entry of the map, as article 13 shows.

A repeatable test through the script handler A repeatable test through the script handler
A repeatable test through the script handler

Two limits apply. The script under test runs without its launch point, so launch point variables are missing. And the same rule as above holds: a script that saves its own sets commits them.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
ASSET alonemakes a new assetonly when the launch point adds records; otherwise loads the first asset
The Process Logshows all logs that use serviceonly service.log, service.logError, print and the error message
The enterprise service exampleSYNC.MXITEMINTERFACE.EXTEXITINthe name needs the dot: EXTEXIT.IN
The condition testshows True or Falsethe result is thrown away
The role testa plain where clauseneeds the OBJECT[where] form

Article 33 of this series collects the corrections that matter most.

What comes next
#

Article 31 covers debugging scripts and the warnings framework.

IBM’s own pages are the reference to keep next to this series:

The complete list of corrections, with the evidence for each one, is in our member area. Members get access on request, so get in touch if you want it. If you want help with the scripts in your own Manage, our services page shows how we work.

IBM and Maximo are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.

Maximo Automation Scripts - This article is part of a series.
Part 30: This Article