↓ Skip to main content
An ink and watercolour drawing of a brass wind-up alarm clock with two bells and a wooden hourglass with running sand on a workbench. In front of them lie five small paper slips in a row; four carry a teal square stamp mark and the fifth is blank.

Cron Task and Async Job Scripts

Maximo Automation Scripts - This article is part of a series.
Part 26: This Article
Some scripts run with no record and no user at the screen. A cron task script runs on a schedule. An async job script runs once, in the background, after something submitted it. This article covers both, and the failures that stay silent because nobody is watching.

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:

ParameterHolds
SCRIPTNAMEthe script to run; read again at every run
SCRIPTARGfree text for the script

Each instance runs one script, so one cron task can serve many scripts, one instance each.

The script gets:

VariableHolds
runAsUserInfothe run-as user of the instance; note the capital A
argthe SCRIPTARG text; convert it yourself, for example with int(arg)
instanceNamethe cron task and its instance, as CRONTASKNAME.INSTANCENAME
scriptName, serviceas 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.

The life of an async script job The life of an async script job
The life of an async script job

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
#

VariableHolds
whereclausethe where clause of the job; IBM Docs calls it where, which does not exist
mbonamethe object name of the job
userInfothe user who submitted the job
jobqnum, scriptNamethe 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
#

TopicIBM’s pagesWhat Manage does
The parameter nameSCRPTNAME in one stepSCRIPTNAME
Setting the parametercreates the scriptonly looks it up; a missing script is logged
The run-as variablerunasUserInforunAsUserInfo, with a capital A
The session samplecounts the sessionsnever cleans up its set
The async variablewherewhereclause
The async handlerScriptAsynchJobHandlerScriptAsyncJobHandler; the other spelling was missing on our test system
The async sampleservice.getMboSet on ASYNCSCRIPTexecute() 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:

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