↓ Skip to main content
An ink and watercolour drawing of a small wooden conveyor belt on a workbench carrying five wooden blocks from left to right under three hand stamps on wooden posts, inked orange, teal and rose. The first block is plain, the next two carry an orange mark, and the last two carry an orange and a teal mark.

Object Structure Scripts: The Inbound and Outbound Hooks

Maximo Automation Scripts - This article is part of a series.
Part 19: This Article
An object structure script hooks into the structure itself. The inbound script runs whenever a message comes in, and the outbound script runs whenever a record is written out. That covers REST, imports, enterprise services and channels at once. This article shows the hooks, in order, and what the context object offers in each.

We checked IBM’s object structure pages against the behaviour of Manage in the MAS 9.2 series, and we checked the methods of IBM’s examples on our test system. Where the pages and Manage disagree, this page follows Manage.

One script, every use
#

An inbound script is named OSIN.<STRUCTURE>, and an outbound script OSOUT.<STRUCTURE>. The name attaches it to the structure, and the save fails when the structure does not exist.

The reach is wide:

  • Inbound: a REST POST, a data import and an enterprise service all end in the same processing, where the inbound hooks run.
  • Outbound: the XML of the channels and the JSON of the REST API both go through the outbound hooks. So an outbound script also changes REST GET responses.

A processing class in Java and a script can work on the same structure together. For a REST call or an import, the object structure’s processing is the only place for custom logic. An enterprise service also has its exits, as article 18 shows.

Both scripts work through named functions. Each function receives ctx as its only argument, and the script needs the Interface flag, which Manage sets on the first save of an OSIN. or OSOUT. name. A function that the script does not define is simply skipped.

The inbound callbacks, in order
#

When the inbound callbacks run When the inbound callbacks run
When the inbound callbacks run
  • beforeProcess runs once for each noun, before any record is read or created. Nothing heavy has run yet, so it is the cheapest place to drop a noun.
  • The five per-object functions run for every object of the noun, on every level.
  • preSaveRules runs once per noun, after the objects are processed.
  • changeStatus runs only when the processing class is StatefulMicSetIn or a subclass of it, and only when the message changes the status.
  • afterProcess runs once per message, after every noun is saved. IBM’s object structure pages never list it. Their workflow page uses it.

A first example drops items that have no lot type:

def beforeProcess(ctx):
    if ctx.getData().getCurrentData("LOTTYPE") == "NOLOT":
        ctx.skipTxn()

The ctx methods that matter
#

MethodWhat it really does
getData()the message; for JSON, an object with the same reading methods
skipTxn()drops the current noun only; the next noun is processed, and the reply is still success
skipMbo()works in mboRules; on the root object it drops the whole noun
complete()in mboRules: stops here, and no children are processed
processAsAdd(), processAsUpdate()on the root, only when the message type is neither Create nor Update
processAsAddAtEnd()adds the record at the end; IBM writes processAsAtEnd, which does not exist
bypassMbo()read only after beforeMboData, when the record exists; the message values are then not copied
getMsgType()returns None: the framework never fills it. Set it in beforeProcess, for example with setMsgTypeSync()
getParentMbo()None in the two data functions; use ctx.getMbo().getOwner() there
getPrimaryMbo()None in beforeProcess and mboRules
setMboSet(), setMbo()build the set or find the record yourself, from beforeCreateMboSet
setProcessTable()changes the table to process, in beforeProcess

The most important line is skipTxn(). IBM’s pages say it skips the whole message. It skips one noun: a message with five items and one skip still loads four.

setSkipBaseAdditionalRules() in preSaveRules has a side effect worth knowing. It skips the additional rules of the Java class, and for status processing that includes the status change and the changeStatus function.

Values that stick
#

The integration framework sets each field from the message with delayed validation. A field set that way is locked: a later setValue on it returns without an error and without an effect.

This decides where a script sets a value:

  • In beforeMboData, the script runs before the message values are copied. A value it sets there with delayed validation locks the field, and the message value is then skipped.
  • In afterMboData, the message values are already in place and locked. A script that sets such a field there is silently ignored. Mark the field Set Restricted in the object structure, and the framework leaves it to the script.

IBM’s third variant clears the lock on one field and then sets another, so its value is still ignored.

The outbound functions
#

An outbound script has three functions, called for every record on every level, in this order:

FunctionUse
skipMbo(ctx)drop the record from the message; on the header record, the whole message
overrideValues(ctx)change the values written, with ctx.overrideCol
skipCols(ctx)leave attributes out, with ctx.skipCol
def skipMbo(ctx):
    if ctx.getMboName() == "POLINE" and ctx.getMbo().isNull("itemnum"):
        ctx.skipMbo()

def overrideValues(ctx):
    if ctx.getMboName() == "PO":
        ctx.overrideCol("DESCRIPTION", ctx.getMbo().getString("description").upper())

Four details:

  • The record stays as it is. An override changes only the output.
  • Write the attribute in upper case for overrideCol. The writer looks it up that way.
  • overrideValues also runs for a record that skipMbo dropped.
  • The outbound ctx has no getUserInfo(). On our test system the method was missing. Use ctx.getMbo().getUserInfo().

For REST output, ctx.getJsonRequest() returns the REST request, so the script can read its query parameters and headers. Neither IBM page names it.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
skipTxn() inboundskips the messageskips the current noun; the others load
getMsgType()gives the message typeNone unless the script set it
processAsAtEnd()adds at the enddoes not exist; the method is processAsAddAtEnd()
getUserInfo() outboundworks inbound and outboundmissing on the outbound ctx
The callbackseight functionsnine: afterProcess runs once per message after the save
The issue type exampleskips other issue typesits NOT IN (...) test is SQL, so the JavaScript does not compile

Article 33 of this series collects the corrections that matter most.

What comes next
#

Article 20 covers endpoint scripts: the HTTP, SOAP and JMS handler exits.

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