This is the first article of Part 2 of our series on automation scripts. Part 1 covered the foundations; the overview lists every part. We checked IBM’s pages about object launch points against the behaviour of Manage in the MAS 9.2 series. Where the two disagree, this page follows Manage.
Five event types, one per launch point#
An object launch point has exactly one event type. Only the save type combines events: it can run on add, on update and on delete, in one context.
| Event type | When it fires | The script gets | Typical use |
|---|---|---|---|
| Initialize | every time a record is loaded or created | mbo | defaults, calculated fields, field flags |
| Validate application | whenever the record is validated, also at the start of every save | mbo | checks before anything is written |
| Allow creation | before a new record is added to a set | mboset, no mbo | refuse a new record |
| Allow deletion | when someone deletes a record, before it is marked | mbo | refuse a delete |
| Save | when the record is saved: on add, update or delete | mbo | logic tied to the save, see below |
So one launch point cannot run on initialize and on save. For that, create two launch points for the same script.
Initialize#
The initialize event fires for every record that Manage loads from the database, and for every new record. It runs after the object’s own initialization code. It is the place for defaults, calculated fields, and fields that become read-only, required or hidden.
It also fires very often. A list of work orders loads many records, and the script runs once for each of them. Keep an initialize script short.
Validate application#
The validate application event fires whenever the record is validated as a whole. A save does that first, so the event also fires at the start of every save. The script runs before the object’s own validation code.
This makes it the right place for checks that must hold before anything is written. In a save, it runs before every other script of the object.
Allow creation and allow deletion#
These two events decide whether a record may be added or deleted at all.
- Allow creation runs before the new record exists. The script has no
mbo, onlymboset, the set that the new record would join. Its owner,mboset.getOwner(), is the record above it, for example the PO when a PO line is added. - Allow deletion runs when someone deletes a record, before Manage marks it for delete. The script
has
mbo, andondeleteis still false at this moment.
The initialize event is too late to refuse a new record, because the record is already in the set by then. Use allow creation for that.
Save#
The save type runs on add, on update and on delete. A record in a save goes to exactly one of the three. Delete wins over add, and add wins over update. Each save launch point also has a context: before save, after save or after commit. Article 7 of this series shows how to choose.
What an error does depends on the context:
- Before save: the save stops, and the transaction is rolled back.
- After save: the database has run the SQL, and the transaction is rolled back.
- After commit: the data is already committed. Manage writes the error to the log, and the user sees nothing.
After save and after commit, Manage writes no OUT or INOUT variable back to the record.
The order of one save#
When a user saves a record, the events and the object’s own code run in a fixed order:
Two points in this order matter for design:
- A before save script runs after the object’s own save code. Values that the script sets still go into the SQL, but the object’s code has already made its own decisions.
- Validate application runs first. A check there sees the record before any save logic has changed it.
When an event does not fire#
Four cases surprise people, because the script is configured and still does not run, or another script runs in its place.
- Allow creation and allow deletion can be bypassed. Code that adds or deletes a record with the access check switched off skips both scripts. A delete of a new record that was never saved skips allow deletion as well.
- Only one allow creation script runs per object. You can define two launch points for it, and Manage keeps only one: the last one by script name and launch point name. The other is silently ignored, and the conflict warning does not report it. The same holds for allow deletion.
- A launch point condition is ignored where there is no record. Allow creation has no
mbo, so a condition on it is never tested, and the script always runs. - An inactive launch point has no listener. It does not fire until you activate it again.
Non-persistent objects#
A non-persistent object, such as the object behind the change status dialog, never reaches the database. Its launch points work differently:
- A save launch point on add or update fires when the dialog’s set is executed. The script gets
mboset. The context does not matter here: before save, after save and after commit all mean “on execute”. - An initialize launch point can also fire once when the dialog is set up, before its records
exist. This is off by default. The system property
mxe.script.callsetuponinitset to 1 switches it on. The script then seesonsetupas true,mboas empty, and fills the set throughmboset.
The setup call has two limits. An error in a setup script is only written to the log, so
service.error never reaches the user there. And for one non-persistent object, only one setup
script runs.
What IBM’s pages get wrong here#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
| Combining events | one launch point can listen to several events | one event type per launch point; only save combines add, update and delete |
| Allow creation | only one launch point can be defined | you can define more; the last one silently wins |
| Allow creation and deletion | they always decide whether a record can be added or deleted | code that switches the access check off skips them |
| On delete | the page describes it as an update event | it fires for records marked for delete |
| Examples | the init and allow deletion examples | they use true and !, which Jython does not know; write True and not |
Article 33 of this series collects the corrections that matter most.
What comes next#
Article 7 picks the moment: before save, after save or after commit, and what each one costs.
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.
