The previous article mapped every method of service.
This one goes deeper into the methods that reach the user. We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series, and we ran the doubtful calls on our test system. Where the pages and
Manage disagree, this page follows Manage.
Three ways to raise an error#
| Way | When the error is raised | OUT variables |
|---|---|---|
service.error(group, key) or (group, key, params) | at once, on that line | not written back |
the variables errorgroup, errorkey and params | after the script has ended | not written back |
| any other exception, such as a typo in a name | at once | not written back |
All three stop the work that started the script. In a before save script, the save fails. After commit, the data is already saved, and the error is only logged. Article 7 shows that difference.
The first two raise your own message from the message table, by group and key. The params fill the
places {0}, {1} and so on in the message text. The third raises a general script error, and the
details go to the log.
Use service.error. It stops the script on the line that found the problem, so no later code
runs by mistake. The variables still work, and they have one trap: the group variable is called
errorgroup. IBM’s service pages write errorgrp. We set errorgrp with an errorkey on our test
system, and the script ended normally, with no error at all.
Warnings#
A warning leaves the work running. The user sees the message, and the save goes on. There are two ways to raise one:
service.setWarning(group, key, params)adds the warning to the record’s set at once. PassNoneasparamsfor a message without parameters.- The variables
warngroup,warnkeyandwarnparamsdo the same after the script has ended. Neither IBM page names them.
Two traps:
- A warning needs a record. In a cron task, or in a library script called without a record,
setWarningfails with a NullPointerException. - Pass
warnparamsas a list. As a Java string array, the parameters are lost, and the warning takes the errorparamsin their place. We saw that on our test system. A Jython list works.
A REST client gets the warnings in a warnings array of the response, each with its group, key and
message. A common check before you raise a warning is if interactive:, so that background runs stay
quiet.
Yes, no and cancel questions#
A script can ask the user a question and act on the answer. In IBM’s design, the answer arrives in a second run of the same script:
The parts that a script uses:
service.yncerror(group, key)or(group, key, params)raises the question. The message defines the buttons.service.yncuserinput()returns the answer, and takes no arguments. Before an answer it returnsYNC_NULL.- The answers are the constants
YNC_NULL(-1),YNC_OK(2),YNC_CANCEL(4),YNC_YES(8) andYNC_NO(16). There is no constant for Close. The REST layer gives Close the value 1.
Manage stores the answer per user under the name of the script and its launch point. It finds the answer only on the server that holds the user’s session.
A common shape maps each answer to a function:
def ask():
service.yncerror("asset", "assetpr")
def yes():
global v, v_required
v = "A0001"
v_required = True
def no():
global v, v_required
v_required = False
if interactive:
actions = {service.YNC_NULL: ask, service.YNC_YES: yes, service.YNC_NO: no}
actions.get(service.yncuserinput(), ask)()Four details make this shape work:
vmust be OUT or INOUT. The functions setvandv_required. For an IN variable, both changes are lost.- The functions need
global. In Jython, an assignment inside a function creates a local variable. Without thegloballine,yes()changes nothing that Manage reads. - Use
.getwith a default. A message that also has a Close button can answer 1, and a plain dictionary lookup then fails with a KeyError. - Check
interactivefirst. In a run without a record, such as a REST script call, we sawyncuserinput()fail with a NullPointerException.
The question also reaches REST clients. The error response carries the question’s id and its buttons.
What IBM’s pages get wrong here#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
| The error variable | errorgrp | errorgroup; errorgrp raises nothing |
yncuserinput | takes group, key and params | takes no arguments; the documented call fails with a TypeError |
| The interactive check | a variable interaction | the variable is interactive; interaction does not exist |
| The yes/no example | sets the vendor through v | works only when v is OUT or INOUT |
| IBM Docs’ copy of the yes/no script | shows the script | never calls yncerror or yncuserinput, so it asks nothing |
The two IBM pages also disagree on the message type for a question: informational on one page, warning on the other. The server reads only the message’s buttons.
Article 33 of this series collects the corrections that matter most.
What comes next#
Article 13 covers library scripts and function calls.
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.
