↓ Skip to main content
An ink and watercolour drawing of an orange wooden key rack standing on a workbench, with six teal hooks under six blank teal name plates. Five keys of different colours hang on their hooks. The fourth hook is empty, and its key lies on the bench below it.

Scripts Manage Runs by Name

Maximo Automation Scripts - This article is part of a series.
Part 10: This Article
Some automation scripts need no launch point. Manage looks for a script with a certain name and runs it when the moment comes. This article covers the names in the object area, one of which IBM never documented, and the naming rule that keeps your own scripts clear of them.

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 nameWhen Manage runs itThe script gets
OBJECT.NEWonce, after a new record is addedmbo, the new record
OBJECT.SAVEbefore every save of a record, ahead of the object’s own save codembo
OBJECT.DUPLICATEwhile a record is copied, before its child records are copiedmbo and dupmbo
OBJECT.AFTERDUPLICATEafter the duplicate action of the REST APImbo and dupmbo
any name, in a relationshipwhen code asks for that relationshipmbo, 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.

Where the by-name scripts run in the life of a record Where the by-name scripts run in the life of a record
Where the by-name scripts run in the life of a record

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.

  • .DUPLICATE runs 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 example POLINE.DUPLICATE. A few objects build their copy by hand, field by field, and for them it never runs.
  • .AFTERDUPLICATE runs 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 calls mbo.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:WOSMARTREL

The 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
#

TopicIBM’s pagesWhat Manage does
OBJECT.SAVEnot mentionedruns before every save of the object, with no launch point
Relation script contextgetParameter("param1")no such method; use getProperty("param1")
script: in the where clause“must contain” the expressionmust start with it, and hold nothing else
.AFTERDUPLICATEruns after a duplicateruns 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:

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.

Maximo Automation Scripts - This article is part of a series.
Part 10: This Article