↓ Skip to main content
An ink and watercolour drawing of three small objects on a workbench: a carved wooden hand on a stand pointing to the right, a red pennant flag on a teal base, and a small wooden abacus with rows of orange, teal and plain beads.

Roles, Error Hooks and Formulas: The Smaller Script Types

Maximo Automation Scripts - This article is part of a series.
Part 27: This Article
Four smaller script types fill gaps that Maximo once closed with Java: a role that finds its people by logic, a hook on an error message, a function for formulas, and a rule language of its own. Each hangs on a naming rule, and each fails quietly when one detail is off.

We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series, and we checked the class and method names of IBM’s samples on our test system. Where the pages and Manage disagree, this page follows Manage.

Role scripts
#

A role decides who gets an assignment or a notification. A role script decides it by logic.

The set-up. Create a role of type custom class with the value com.ibm.tivoli.maximo.script.ScriptCustomRole. Then create a script without a launch point named MAXROLE.<ROLE>. The lookup is case-sensitive, so write the role name as it is stored, normally in upper case. Tick “Allow Invoking Script Functions”: without it, the script body runs, defines its functions and calls none, and the role resolves to nobody, with no error.

The functions. Manage calls evalToPerson(ctx) to find a person or a group, and evalToEmail(ctx) to find mail addresses:

  • evalToPerson alone is enough. Without evalToEmail, the mail path uses the person’s address, or the addresses of the group’s members.
  • evalToEmail can add addresses that belong to no person record.
  • Without evalToPerson, the role resolves to nothing.

Inside the functions, service and mbo do not exist. The ctx object offers both:

Method on ctxUse
getMbo()the record the role is resolved for
setPersonOrGroupMbo(rec)the answer: a person record, or a person group
addEmailId(address)adds one mail address
getEmailIds()the added addresses; None when none were added
getMaxRole()the role record
def evalToPerson(ctx):
    rec = ctx.getMbo()
    name = "TIER1" if rec.getString("siteid") == "BEDFORD" else "TIER2"
    groups = rec.getMboSet("$ROLEGROUP", "PERSONGROUP", "persongroup = '" + name + "'")
    ctx.setPersonOrGroupMbo(groups.moveFirst())

A person group as the answer resolves to the people of the group. An inactive script resolves the role to nobody, again with no error.

Error hooks: MXERR scripts
#

An MXERR script runs when Manage creates an error with a given group and key. It can add text to the message or report the error elsewhere.

The name is MXERR.<GROUP>.<KEY>, in upper case: MXERR.SYSTEM.INVALIDSITE matches the group system with the key invalidsite. One script covers one pair, and there is no wildcard for a whole group.

The moment is the creation of the error, before anything throws it. So the script also runs for errors that the product creates and then catches. It does not run before the server has started, or while the script cache is loading. Keep such a script cheap, because it runs for every error of its key.

What happens when Manage creates an error What happens when Manage creates an error
What happens when Manage creates an error

The script gets egroup (in lower case), ekey, eparams (the message parameters, or None) and emsg, the formatted message. Neither IBM page names emsg. There is no record and no user, so a script that wants the user has to find it another way.

To add text, declare an OUT variable mxerrormsg. Its value is appended to the message after a space:

# MXERR.SYSTEM.INVALIDSITE, with an OUT variable mxerrormsg
mxerrormsg = "Check the default insert site in your profile."

An error inside the MXERR script is only printed to the console, so a broken script never changes the error. IBM’s mail example has two faults. It calls sendEmail, but the method is sendEMail; on our test system sendEmail was missing. And it tests with ekey="something", an assignment, so the script cannot be saved. Use ==.

Formula functions
#

A formula computes a number from a record. A script can add a function to the formula library.

The registration is a function row with the implementation type script and the script name as the implementation name, exactly as the script is stored. A missing script fails when the formula is parsed.

The script gets:

VariableHolds
mbothe formula’s record
paramsthe arguments, as a Java list of BigDecimal
ctxthe function itself
expthe parsed expression

A text argument arrives as a number: the hash code of the text. ctx.getExpression().getCalculatedValue(params[0]) turns it back into the text, as IBM’s sample does.

The result goes into evalresult, and it must be a number:

evalresult typeResult
Integer, Long, Short, BigInteger, Doublethe number
Dateits milliseconds
Stringits hash code
Float, Boolean, anything elseNone

So return 1 or 0 for a yes or a no. Within one formula run, the result is cached per function, record and arguments. To test a formula over REST, select it as exp.<formulaname> in oslc.select.

MBR in short
#

MBR, the Maximo business rule language, is a script language with its own driver. Each line is one expression, a line that starts with a colon opens a function, and launch points, bindings and implicit variables work as in Jython. Three things to know:

  • Library names in upper case. invokescript("createmeters") checks the name in upper case, but calls it as written. The lower-case call finds no script and fails with a NullPointerException. Write invokescript("CREATEMETERS").
  • No access checks. newmbo and setvaluetombo add and set without access checks.
  • A year is 365 days in duration. A date one year later lands a day early when 29 February is in between.

Article 10 covers the duplicate hook that IBM’s third MBR example uses.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
The mail call in MXERRsendEmailsendEMail; the other spelling was missing on our test system
The MXERR testekey="something"an assignment; the script cannot be saved
MXERR variablesegroup, ekey, eparamsalso emsg, the formatted message
Role functionsdeclare one of the twoevalToPerson alone covers both paths
Formula resultsnot listedonly number types and dates; Float and Boolean give None
An MBR library callinvokescript("createmeters")fails in lower case; write the name in upper case

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

What comes next
#

Article 28 covers attachment store scripts.

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