The last articles were about launch points. This one closes Part 2 of the series with the scripts that work without one. We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series. Where the two disagree, this page follows Manage.
The names Manage acts on#
For a record of an object, Manage looks for five kinds of names:
| Script name | When Manage runs it | The script gets |
|---|---|---|
OBJECT.NEW | once, after a new record is added | mbo, the new record |
OBJECT.SAVE | before every save of a record, ahead of the object’s own save code | mbo |
OBJECT.DUPLICATE | while a record is copied, before its child records are copied | mbo and dupmbo |
OBJECT.AFTERDUPLICATE | after the duplicate action of the REST API | mbo and dupmbo |
| any name, in a relationship | when code asks for that relationship | mbo, and it sets mboset |
OBJECT is the object’s own name: PO.NEW for a purchase order. For an object that is based on a
view, such as WOACTIVITY on WORKORDER, the name of the view object counts. A WOACTIVITY record looks
for WOACTIVITY.NEW and never for WORKORDER.NEW.
A script without a launch point takes its variables from its own variable list, bound against mbo.
OBJECT.NEW: the place for defaults#
OBJECT.NEW runs once for each new record, as the last step of the add. Before it come the
initialize scripts of the object, the defaults from the database and the application, and the
fixed field flags. So a .NEW script can overwrite every other default.
It never runs when a record is loaded from the database. That makes it the better place for
defaults than an initialize launch point, which runs on every load and every add. onadd is true in
a .NEW script, and the owner of the set is available through mbo.getOwner(). IBM’s example
copies a field from the owner PO to a new PO line.
OBJECT.SAVE: undocumented, and easy to hit#
A script named OBJECT.SAVE runs before every save of a record of that object. It needs no
launch point. Manage calls it right before the object’s own save code, with mbo set. Neither of
IBM’s two documents mentions this name.
This has a sharp consequence for naming. Naming a before save script ASSET.SAVE, and its launch
point the same, looks natural, and at least one public guide recommends it. With that name, the
script runs twice for every saved asset:
- Once by name, before the asset’s own save code. This run has no launch point, so the launch point’s variable overrides and its condition do not apply.
- Once through the launch point, in the before save phase.
Twice the cost, and every side effect happens twice. So never give a script with a launch point a name that Manage acts on.
OBJECT.DUPLICATE and OBJECT.AFTERDUPLICATE#
Both run when a record is copied. They get the original record as mbo and the new one as dupmbo.
.DUPLICATEruns inside the copy itself. Every copy runs it: from the screen, from a script, or from an integration. It runs before the child records are copied, and before the new record gets its automatic key values. Each copied child then runs its own.DUPLICATE, for examplePOLINE.DUPLICATE. A few objects build their copy by hand, field by field, and for them it never runs..AFTERDUPLICATEruns after the whole duplication, so the copied child records exist. In the code we read, the duplicate action of the REST API fires it. A script that callsmbo.duplicate()does not.
Use .DUPLICATE to clear values on dupmbo that should never be copied. Use .AFTERDUPLICATE for
work on the copied children.
Relation scripts#
A relationship can be answered by a script instead of SQL. Its where clause names the script:
script:WOSMARTRELThe clause must start with script:, in lower case and with no blank in front. Everything after the
colon is the script name, so the clause holds nothing else. A clause with script: further inside
runs as plain SQL.
The script gets the source record as mbo, the user as userInfo, and the relationship itself as
ri. It must put the result set into mboset. When it sets nothing, the caller gets nothing.
Manage does not cache the result, so every request for that relationship runs the script again.
A REST call can pass values to such a script with the ctx parameter, as in ctx=param1=value1.
Each pair becomes a property of the integration context. Read it with getProperty("param1").
IBM’s two examples use getParameter, which does not exist, so they fail.
Names that are taken#
Integration, REST, role and error scripts use more names, and later parts of this series cover them:
OSIN., OSOUT., PUBLISH., INVOKE., .OUT, .EVENTFILTER, OSACTION., APISYSACTION.,
MAXROLE. and MXERR..
Every one of these names contains a dot. That gives a simple rule for your own scripts: use no dot
in a script name. A scheme such as OBJECT_EVENT_PURPOSE_NN, for example
WORKORDER_SAVE_AUTOASSIGNCREW_01, stays clear of every name that Manage acts on. Article 29 of this
series covers naming in a larger script estate.
What IBM’s pages get wrong here#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
OBJECT.SAVE | not mentioned | runs before every save of the object, with no launch point |
| Relation script context | getParameter("param1") | no such method; use getProperty("param1") |
script: in the where clause | “must contain” the expression | must start with it, and hold nothing else |
.AFTERDUPLICATE | runs after a duplicate | runs after the REST duplicate action; a script’s own duplicate() does not fire it |
Article 33 of this series collects the corrections that matter most.
What comes next#
This ends Part 2. Part 3 starts with the service object: every method it offers in the 9.2 series.
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 inventory of what the script engine does without documentation 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.
