↓ Skip to main content
An ink and watercolour drawing of a short wooden ramp on a workbench sloping toward a small wooden gate with a hinged flap. A teal and an orange envelope still wait on the ramp, a teal and an orange envelope lie past the gate in an open wooden tray, and a rose envelope lies in a small wicker basket beside the gate.

Publish Channels, Event Filters, Workflow and MDB Scripts

Maximo Automation Scripts - This article is part of a series.
Part 21: This Article
A publish channel sends Manage’s changes to other systems. Scripts decide which events go out, change the message on its way, start a workflow after an inbound message, and read messages from an external queue. This article covers those four jobs, and the traps in each.

This article closes Part 5. We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series. Where the pages and Manage disagree, this page follows Manage.

From event to message
#

The path of an event through a publish channel The path of an event through a publish channel
The path of an event through a publish channel

The filter runs first, before the record is serialized. That makes it the cheapest place to drop an event. A channel processing rule could drop it too, but rules run on the serialized message, after that cost is spent.

The event filter
#

The filter script is named PUBLISH.<CHANNEL>.EVENTFILTER, in upper case. It runs from the channel’s default event filter class. A channel with its own Java filter class runs the script only when that class calls the filter method of the default class. A class that replaces the method without that call never runs the script.

The result goes in evalresult, and its meaning is the reverse of what the name suggests:

evalresultEffect
Truethe event is dropped
Falsethe event is published
not setthe default checks of the filter class decide

Setting evalresult at all also switches off two default checks of the filter class: the check for recurring events and the check for the record hierarchy. A script that sets it takes over the whole decision.

# PUBLISH.MXWOINTERFACE.EVENTFILTER: publish only status changes to APPR
evalresult = True
if mbo.isModified("status") and mbo.getString("status") == "APPR":
    evalresult = False

Three more facts:

  • mbo is the event record. IBM’s pages say a bug hides mbo here and recommend service.getMbo(). In the 9.2 series, both work.
  • The filter has no message. irData, messageType, extSystem and conn do not exist here. ifaceName, osName, userInfo and interactive do.
  • Only event-based channels filter. A channel used for export has no listener, so no filter runs.

IBM’s best-practice page has a filter sample whose last line sets evalresult = True on every path, so it drops every event. Put that assignment in an else, or set it first, as above.

Publish channel exits
#

Article 18 lists the names, the order and the variables of the exits. Two points belong to publish channels.

An external exit can just change irData. When the script leaves erData empty, the changed irData becomes the message. IBM’s asset example works this way.

Walking the children. IBM’s job plan example sets a description on each job task in a before user exit. Its loop calls logger.info, but no variable logger exists, so the script fails with a NameError. The IBM Docs copy also drops the last line, which leaves the last job task as the current object. With service.log and the last line kept:

tasks = irData.getChildrenData("JOBTASK")
for i in range(tasks.size()):
    irData.setAsCurrent(tasks.get(i))
    irData.setCurrentData("DESCRIPTION", "Task " + str(i + 1))
    service.log("job task " + str(i + 1) + " renamed")
irData.setParentAsCurrent()

setAsCurrent with the child object works for XML and JSON channels. The other form, setAsCurrent(list, index), works for XML only and fails for JSON.

A workflow after an inbound message
#

An inbound object structure script can start a workflow once the message is saved. The function for that is afterProcess, which runs once per message, after the save:

from psdi.server import MXServer

def afterProcess(ctx):
    wo = ctx.getPrimaryMbo()
    if wo.isNew() and wo.getString("status") == "WAPPR":
        MXServer.getMXServer().lookup("WORKFLOW").initiateWorkflow("WOSTATUS", wo)

The script is OSIN.MXWODETAIL, so it runs for a REST POST to that structure as well. Two details:

  • isNew() stays true after the save, so it still tells a new work order from an update.
  • With several nouns in one message, ctx.getPrimaryMbo() returns the record of the last noun.

Inside the function, service does not exist. ctx offers its methods.

Scripted message-driven beans
#

A message-driven bean can read messages from an external JMS queue and hand each one to a script. IBM’s page shows the setup: a bean with the class psdi.iface.jms.JMSScriptListenerBean and an env-entry named SCRIPTNAME. The script gets:

VariableHolds
jmsmsgthe JMS message
userInfothe user the bean runs as
mdbctxthe bean’s context

Two facts decide whether messages survive:

  • The script name must match exactly. The bean reads SCRIPTNAME once, at start. Without an active script of exactly that name, it logs an error and returns. The message counts as received, and it is lost.
  • A script error keeps the message. An error marks the transaction for rollback, so the message comes back to the queue.

So activate and test the script before the bean starts reading. IBM’s page names only jmsmsg. The IBM Docs copy of the bean’s XML stops before its closing tags.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
mbo in an event filterhidden by a bug; use service.getMbo()bound in the 9.2 series; both work
The filter example’s summarydrops events that did not change a work order to APPRthe example tests an asset for BROKEN
The best-practice filter samplefilters by statussets True on every path and drops every event
The job task exitlogs with logger.infono logger exists; NameError
The scripted MDBonly jmsmsgalso userInfo and mdbctx; a missing script loses the message

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

What comes next
#

This ends Part 5. Part 6 is about REST API scripts: your own endpoint, how to protect it, and the object structure actions and queries.

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