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: PATCHWhat the action gets#
| Variable | Holds |
|---|---|
mbo | the record of the URI, when the call loaded one; otherwise None |
mboset | the set of that record, or the set of the collection |
request, httpMethod | the request and its method |
requestBody | the body as text; None when it is empty, and no body is read on GET |
app, scriptName, actionName, userInfo | named by neither IBM page |
responseHeaders | a 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:
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#
responseBodycan 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=APPRFour 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.savedQuerytakes 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.boktestattrThe 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 = valuesOn 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. ANonevalue 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#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
| The SENDCOMM call | a POST to the record | a plain POST leaves mbo as None; the PATCH header is required |
| Collection Action | an action on the set that needs no record | decides only where the action is listed |
| The action’s variables | five variables | also app, scriptName, actionName, userInfo and responseHeaders |
| The action’s output | not described | OUT and INOUT literal variables come back as JSON |
| The IBM Docs query example | add the query to MXAPIWO | the 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:
- Automation scripts in the IBM Maximo Manage documentation.
- All about Maximo scripting, IBM’s scripting guide on GitHub.
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.
