We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series, and we checked the class and method names of IBM’s samples on our test system. Where the pages and Manage disagree, this page follows Manage.
The script cron task#
Manage ships a cron task class for scripts, com.ibm.tivoli.maximo.script.ScriptCrontask. It
behaves like any other cron task: an instance, a schedule, a run-as user, active or not. It has two
parameters:
| Parameter | Holds |
|---|---|
SCRIPTNAME | the script to run; read again at every run |
SCRIPTARG | free text for the script |
Each instance runs one script, so one cron task can serve many scripts, one instance each.
The script gets:
| Variable | Holds |
|---|---|
runAsUserInfo | the run-as user of the instance; note the capital A |
arg | the SCRIPTARG text; convert it yourself, for example with int(arg) |
instanceName | the cron task and its instance, as CRONTASKNAME.INSTANCENAME |
scriptName, service | as usual |
There is no mbo. The script opens its own sets.
Errors that nobody sees#
Every error in a cron task script is caught and logged, and the cron task run counts as done. Nobody gets a message. So log clearly, with the instance name in the line, and read the log.
A missing script is just as quiet. IBM’s guide says that setting the parameter creates the script. It does not: the run looks the script up, and when it is missing, the run logs “no such script”.
A cron script that owns its sets#
IBM’s sample counts the open sessions and logs an error over a limit. It works, but it never closes
the set it opens. The same check, with the limit from SCRIPTARG and the clean-up in place:
limit = int(arg)
sessions = service.getMboSet("MAXSESSION", runAsUserInfo)
try:
n = sessions.count()
if n > limit:
service.logError("%s: %d sessions, limit %d" % (instanceName, n, limit))
finally:
sessions.cleanup()A cron script that changes data follows the same rule as Manage itself: open one set, open every other set from its records, and save once at the end. Article 15 shows that pattern, and article 17 the clean-up.
Async jobs#
An async job runs a script once, in the background. A cron task picks up the submitted job, runs it, and sets the job to complete or to error.
Submitting a job#
A job is submitted through the non-persistent object ASYNCSCRIPT: call its setup(), set
autoscript to the script name and objectname to the object, optionally set whereclause, and
call execute(). The job then waits for the scheduled async cron task.
One trap decides whether this works. execute() adds the job through the owner of the ASYNCSCRIPT
set. A set from service.getMboSet has no owner, and execute() fails with a NullPointerException.
IBM’s sample does exactly that. Open the ASYNCSCRIPT set from a record instead, so that it has an
owner.
What the job’s script gets#
| Variable | Holds |
|---|---|
whereclause | the where clause of the job; IBM Docs calls it where, which does not exist |
mboname | the object name of the job |
userInfo | the user who submitted the job |
jobqnum, scriptName | the job number and the script name |
Every attribute of the submitted record also comes back as a variable of the same name. Those
variables hold Maximo value objects, and that includes whereclause: the record’s own attribute
replaces the plain text. Treat it as such a value object, as with the _initial variables of
article 4.
Two silent cases#
- Activation does not submit. Activating the script registers nothing. Only
execute()writes the job. - An inactive script still completes. If the script is inactive when the job runs, it is skipped without an error, and the job still ends as complete.
What IBM’s pages get wrong here#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
| The parameter name | SCRPTNAME in one step | SCRIPTNAME |
| Setting the parameter | creates the script | only looks it up; a missing script is logged |
| The run-as variable | runasUserInfo | runAsUserInfo, with a capital A |
| The session sample | counts the sessions | never cleans up its set |
| The async variable | where | whereclause |
| The async handler | ScriptAsynchJobHandler | ScriptAsyncJobHandler; the other spelling was missing on our test system |
| The async sample | service.getMboSet on ASYNCSCRIPT | execute() needs an owner and fails without one |
Article 33 of this series collects the corrections that matter most.
What comes next#
Article 27 covers the smaller script types: roles, error hooks and formulas.
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.
