↓ Skip to main content
An ink and watercolour drawing of an open wooden card-index box full of blank cards on a workbench. Three cards lie fanned out beside it, the top one carrying an orange square stamp mark, next to a wooden rubber stamp and a teal ink pad.

Object Structure Actions and Query Scripts

Maximo Automation Scripts - This article is part of a series.
Part 24: This Article
Three kinds of script extend the object structure API itself. An action script does work on a record or a set. A query script decides which records a request returns. A script attribute adds a computed value to each record in the answer. This article covers all three, and the call that IBM’s own example gets wrong.

We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series, and we called a script attribute on our test system. Where the pages and Manage disagree, this page follows Manage.

Action scripts
#

An action script is created through the wizard: Create, Script for Integration, the object structure, then Action Processing. Its name becomes OSACTION.<STRUCTURE>.<ACTION>. Then the object structure needs a row in its Action Definition dialog: implementation type Script, and this script. The script field accepts only scripts whose names start with OSACTION. and that structure.

The row can name an application and a signature option. A user then needs that option to run the action, and if the option requires an electronic signature, that is checked too.

The call goes to a record or to the collection, with action=<NAME>:

POST /maximo/api/os/mxapiwodetail/<id>?lean=1&action=SETPRIORITY&priority=2
x-method-override: PATCH

What the action gets
#

VariableHolds
mbothe record of the URI, when the call loaded one; otherwise None
mbosetthe set of that record, or the set of the collection
request, httpMethodthe request and its method
requestBodythe body as text; None when it is empty, and no body is read on GET
app, scriptName, actionName, userInfonamed by neither IBM page
responseHeadersa map; here, every entry goes into the answer

When mbo is set
#

The record comes from the URI, and the method decides whether it is loaded:

When an action script gets its record When an action script gets its record
When an action script gets its record

This is where IBM’s example fails. Its SENDCOMM call is a plain POST to a record URI, so mbo is None, and the script’s call mbo.createComm() fails. IBM’s note about the PATCH header is the fix: send x-method-override: PATCH, and the record is loaded. On a child URI, mbo is the child record.

The Collection Action flag in the Action Definition row decides only where the action is listed: in the allowed actions and in the API document. The URI alone decides whether mbo is set.

What the action returns, and the save
#

  • responseBody can be text, bytes, a record or a set. A record or a set is written as REST JSON.
  • Without responseBody, the answer is one JSON object with every OUT or INOUT literal variable of the script. Dates become text.
  • The save is done for you. After the script, a POST or PATCH saves the set of mbo, and an error rolls it back. The script calls no save, as article 15 recommends for every script on a record.

A short action, called with the PATCH header as above:

prio = request.getQueryParam("priority")
if prio and prio.isdigit():
    mbo.setValue("wopriority", int(prio))

A call without a valid number changes nothing, and the save after the script finds no change.

Actions also run on GET. A literal variable allowget with the value 0 blocks that, with the error oslc#postonly.

Query scripts
#

A query script decides which records a request returns, when the REST filters are not enough. Its name is OSQUERY.<STRUCTURE>.<QUERY>, and the object structure needs a query of type script that names it. The field accepts only a script of that same structure.

The script gets mboset and sets its where clause. It also gets one variable per script variable. There is no request, so the script reads its input through those variables:

from psdi.mbo import SqlFormat

sqf = SqlFormat("historyflag = 0 and status = :1")
sqf.setObject(1, "WORKORDER", "STATUS", status)
mboset.setWhere(sqf.format())

status is a literal variable of the script. The caller fills it with a query parameter:

GET /maximo/api/os/mxapiwodetail?lean=1&savedQuery=OSQUERY.MXAPIWODETAIL.BYSTATUS&sqp:status=APPR

Four details:

  • sqp:<variable> passes each script variable. When the parameter is missing, the variable’s literal value is the default. Only a literal variable gets that default, so use literal bindings.
  • savedQuery takes the full script name.
  • The query’s settings decide who may use it. A query that is not public serves only its owner, and a query tied to a role serves only that role.
  • The script runs first. The request’s bounding-box and QBE filters apply after it.

IBM Docs adds the example query to the structure MXAPIWO. Its script is OSQUERY.MXAPIWODETAIL.EMXWOFILTER, so the field on MXAPIWO refuses it. The query belongs on MXAPIWODETAIL.

A computed attribute in oslc.select
#

A script can add a computed value to every record of a GET. Name it in oslc.select as script.<name>:

GET /maximo/api/os/mxapiasset?lean=1&oslc.select=assetnum,siteid,script.boktestattr

The script has no launch point. It gets mbo, the record being written, and sets evalresult:

from java.util import ArrayList

values = ArrayList()
values.add(mbo.getString("assetnum"))
values.add(mbo.getString("siteid"))
evalresult = values

On our test system the answer carried "boktestattr": ["1001", "BEDFORD"]: a Java list becomes a JSON array of strings, under the lower-case script name. Any other value is written as text.

Two traps:

  • Always set evalresult. A None value breaks a JSON request with a NullPointerException.
  • It runs once per record. A page of 100 records runs the script 100 times. Keep it cheap, as article 17 explains.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
The SENDCOMM calla POST to the recorda plain POST leaves mbo as None; the PATCH header is required
Collection Actionan action on the set that needs no recorddecides only where the action is listed
The action’s variablesfive variablesalso app, scriptName, actionName, userInfo and responseHeaders
The action’s outputnot describedOUT and INOUT literal variables come back as JSON
The IBM Docs query exampleadd the query to MXAPIWOthe script belongs to MXAPIWODETAIL

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

What comes next
#

This ends Part 6. Part 7 is about the other script types: actions and conditions in workflow and escalations, cron tasks and async jobs, the smaller types, and attachment store scripts.

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 24: This Article