This article closes Part 4. We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series, and we ran the doubtful call on our test system. Where the pages and Manage disagree, this page follows Manage.
How often a launch point runs#
| Launch point and event | Runs |
|---|---|
| Object, initialize | for every record loaded into a set, on the List tab too, whether a field is shown or not |
| Attribute, initialize value | once per record, on the first read of the field |
| Attribute, validate or action | every time a value is set on the field, by a user or by code |
| Object, save events | on every save, from an application, an integration, a workflow or another script |
Two rows deserve a second look.
Object init is the expensive one. A set that reads 500 records runs the script 500 times. For a value that one field shows, IBM’s pages recommend the attribute event Initialize Value. It runs only when someone reads the field, and only once per record.
Attribute scripts run once per value set. The script never sees keystrokes. It runs when a value is set on the field, and code sets values far more often than users do: an import, an integration or a script loop sets the field once per record, and the script runs each time. A script that sets a value on a related record runs that record’s attribute scripts too, inside the same call.
Where costly work belongs#
The check for a changed field is short:
if mbo.isModified("STATUS"):
check_status_rules(mbo)check_status_rules stands for your own code. On a save that leaves the status alone, the check is
all the script costs.
A List tab check that works#
IBM’s pages suggest running a costly object init only for a record opened on the Main tab, and
skipping it on the List tab. Their sample calls UIContext.isFromListTab() on the class. That call
fails: the method belongs to the current context object. On our test system it failed with a
TypeError, “expected 1 args; got 0”.
The working form asks the current context:
from psdi.common.context import UIContext
ctx = UIContext.getCurrentContext()
if ctx is not None and not ctx.isFromListTab():
load_details(mbo)load_details stands for your own code. Outside a request from an application, the current context
is None. We saw that in a script called through the REST API. So this check also skips the costly
part for REST, integration and escalation work. If that work needs it, test for None on its own.
The clean-up a script owes#
A set that the script opens itself, with service.getMboSet, belongs to the script. The script has to
close it with cleanup(), in a finally block, so that an error cannot skip it:
s = service.getMboSet("ASSET", userInfo)
try:
s.setWhere("siteid = 'BEDFORD'")
count_assets(s)
finally:
s.cleanup()count_assets stands for your own code. cleanup() resets the set, which closes it, and drops its
transaction. This also closes the database statement that a set can keep open after a partial read, as
article 16 shows for isEmpty().
Two more points:
- Database connections. A script that takes a database connection must free it again, in the same way. Manage even ships a check for this, which compares the calls that take a connection with the calls that free one.
- A safety net exists. With the system property
mxe.script.autocleanupset to true, Manage cleans up every set of this kind that the script still holds in a variable at the end of the run, when the set still has records. It logs a warning with a stack trace to the database connection logger. It covers only scripts that run from the engine’s compiled cache, and a set that no variable holds at the end is missed. So the property finds forgotten clean-ups, and it replaces none. The default is false, and neither IBM page names it.
Article 31 of this series covers the warnings framework, which also counts the clean-up calls.
What IBM’s pages get wrong here#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
| The List tab sample | UIContext.isFromListTab() on the class | fails with a TypeError; call it on UIContext.getCurrentContext(), which is None outside an application |
| The clean-up safety net | not named | mxe.script.autocleanup cleans up root sets still held in a variable after the run |
IBM’s advice to clean up every set from service.getMboSet in a finally block is right. So is the
advice to prefer Initialize Value over object init.
Article 33 of this series collects the corrections that matter most.
What comes next#
This ends Part 4. Part 5 is about integration scripts: the exits of the integration framework and the names Manage looks for.
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.
