↓ Skip to main content
An ink and watercolour drawing of a small orange machine on a wooden workbench. Three glass jars on a shelf above feed it through tubes into one funnel, a lever with a red knob sits on its left side, a card with wavy lines is clipped to its front, two gears show through a round hatch, and a spout on the right pours into a half-full jar.

What an Automation Script Is, and What Happens When It Runs

Maximo Automation Scripts - This article is part of a series.
Part 1: This Article
An automation script is a piece of code that Manage keeps in its database and runs when something happens to a record. This article explains what a script is made of, what Manage does when you save one, and what happens each time it runs.

Automation scripts are the way most Manage customizations are written today. A script needs no Java build, no deployment of a customization archive and no restart. You write it in the Automation Scripts application, save it, and it is active on every server of the installation.

This is the first article of our series on automation scripts. It gives you the model that every later article builds on. We checked IBM’s two documents about scripts, the IBM Docs pages and the scripting guide on GitHub, against the behaviour of Manage in the MAS 9.2 series. Where the two disagree, this page follows Manage and says so.

A script has three parts
#

Every script is built from the same three parts.

  • The script holds the source code and its language. Manage stores it in the database, so it moves with the database.
  • The launch point ties the script to a moment: an event on a record, a change to a field, an action, or a condition.
  • The variables bind data to the script. A variable brings a value in, sends a value out, or does both.
PartWhat it holdsObject in Manage
Scriptname, language, source code, the active flagAUTOSCRIPT
Launch pointthe type, the object or attribute, the event, an optional conditionSCRIPTLAUNCHPOINT
Variablesthe binding: a field, a system property, a MAXVAR or a fixed valueAUTOSCRIPTVARS, LAUNCHPOINTVARS

Here is a script that came with our 9.2 test system, WXOAISUMMARY, on the Launch Points tab of the Automation Scripts application. One script, three object launch points: one on SR, one on INCIDENT and one on WORKLOG.

The Automation Scripts application in Maximo Manage with the script WXOAISUMMARY open on the Launch Points tab. The table Launch Points lists three rows, 1 - 3 of 3: WATSONSRLP on the object SR, WXOAISUMMARY on INCIDENT and WXOWORKLOG on WORKLOG, each of the type OBJECT and active.
One script, three launch points, in the Automation Scripts application on our test system

One script can serve several launch points. A script can also exist with no launch point at all. Then other scripts call it as a library, or a cron task runs it.

Variables are optional. Next to the variables you declare, Manage gives every script a set of implicit variables. The most used ones are mbo (the record the script works on), service (a helper object with methods for errors, logging and calls to other scripts), user and app. Article 4 of this series lists them all, launch point by launch point.

Four kinds of launch point
#

Manage knows four kinds of launch point.

  • Object: an event on a record, such as add, update, delete or save.
  • Attribute: an event on one field, such as a new value or a lookup.
  • Action: a step that a workflow, an escalation or a button calls.
  • Custom condition: a yes or no answer for a workflow or for the user interface.

The IBM Docs overview speaks of five launch point types, each with its own wizard. The fifth wizard is for integration scripts. It names the script after the integration point and creates no launch point, so Manage knows only the four.

Two engines ship with Manage
#

The language of a script decides which engine runs it. Manage ships two engines.

  • Jython, a Python 2.7 for Java. It answers to the language names jython and python.
  • Nashorn, a JavaScript engine. It answers to javascript, js, nashorn and ecmascript.

The scripting guide says that Nashorn comes with the Java runtime. That was true for older Java releases, and the JDK has had no Nashorn since Java 15. Manage in the 9.2 series runs on a much later Java, so it carries its own copy of Nashorn. Both IBM documents also name Jython 2.7.2, and the 9.2 series ships a later release of the 2.7 line. Article 2 of this series compares the two languages.

What happens when you save a script
#

A save does more than write a row. Manage checks the code, stores it, and loads it into a cache of compiled scripts.

The path of a save: check, store, load The path of a save: check, store, load
The path of a save: check, store, load

Three things follow from this path.

  • A compile error blocks the save. You see the error at once, and the old version keeps running.
  • The save waits for the cache. On the server that saved, the script is loaded in the same request, so it is active as soon as the save returns. The other servers reload it a little later.
  • The cache only knows what went through Manage. A change made with SQL directly in the database reaches the cache at the next reload, for example at the next server start.

The scripting guide puts the steps in a different order: compile, cache, then store. The IBM Docs page has the order of the diagram, and so does Manage.

One script can pass the save and still never run
#

The check at save and the load into the cache are two separate compiles. Usually both give the same result. One option makes them differ: Allow Invoking Script Functions. A script with this option is run once when it is loaded, so that other scripts can call its functions later. If that first run fails, Manage leaves the script out of the cache. It writes one line at ERROR level to the log, with the text “Error in compiling script - skipping this script”, and every launch point of the script is skipped.

The user sees no error, and the script simply does nothing. So after you save a script with this option, look in the log for that line.

What happens when the script runs
#

The launch point decides when a script runs. For an object or an attribute launch point, Manage registers a listener when it loads the script. When the event happens, the listener starts the run.

One run of a script, from the event to the written values One run of a script, from the event to the written values
One run of a script, from the event to the written values

The compiled code in the cache is used again for every run. Each run gets its own fresh set of variables, so nothing carries over from one run to the next.

Values go in before the run and come back after it
#

This is the part of the model that surprises people most. Manage copies every variable value into the script before the script starts. It copies the INOUT and OUT values back to the record after the script has ended, and only the values that changed.

So during the script, the record still holds the old value. Suppose a script sets an OUT variable that is bound to the field DESCRIPTION, and then reads mbo.getString("DESCRIPTION"). It gets the old description, because the new one is written after the script ends. Read the variable instead, or set the field on mbo directly when the rest of the script needs the new value.

BindingDirectionWritten back?
A field of the recordIN, INOUT or OUTINOUT and OUT, after the run, when the value changed
A system propertyalways INnever
A MAXVARalways INnever
A fixed valueINnever

When the script fails
#

Two kinds of error reach the user in two different ways.

  • An error the script raises on purpose, for example with service.error(...), reaches the user with its own message.
  • Any other error, such as a typo in a name or a failed call, reaches the user as a general script error. The details go to the log at ERROR level.

The run time of each script is also written to the log, but only when the logger of that script is set to DEBUG. Both IBM documents say that the time is always written. At the default level you find nothing.

Switching a script off
#

You can deactivate one launch point of a script, or the whole script. For a launch point, the effect depends on its kind.

Launch pointWhat happens after you deactivate the launch point
ObjectManage no longer calls the script.
AttributeManage no longer calls the script.
ActionThe workflow, escalation or button still calls it, and the call fails with an error.
Custom conditionThe workflow or the user interface still asks it, and the call fails with an error.

Both IBM documents say that Maximo does not run a deactivated script or launch point. That is true for object and attribute launch points, which simply lose their listener. An action or a condition is called from a workflow, an escalation or the user interface, and that call still happens. So when you switch off an action script, also take it out of the workflow, the escalation or the button that calls it.

Deactivating the whole script works another way. Every launch point stays registered, and each run ends at once with a line at INFO level in the log. A custom condition then gets no answer, and that also ends in an error.

The status of a script, Draft or Active, has no effect on runs. A Draft script runs exactly like an Active one. Only the active flag decides.

What IBM’s documents get wrong here
#

This first part of IBM’s material is mostly right. Four statements are wrong for the 9.2 series:

  • Nashorn comes with the Java runtime. Manage ships its own copy.
  • The run time of a script is always written to the log. It is written only at DEBUG.
  • A deactivated launch point is never called. Action and condition launch points are still called, and the call fails.
  • There are five launch point types. There are four, and the fifth wizard creates none.

Article 33 of this series collects the corrections that matter most, across all of IBM’s material on scripts.

What comes next
#

The next two articles stay with the basics. Article 2 compares Jython and JavaScript in the 9.2 series, and article 3 shows how scripts, launch points and variables fit together in practice.

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