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:
evalToPersonalone is enough. WithoutevalToEmail, the mail path uses the person’s address, or the addresses of the group’s members.evalToEmailcan 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 ctx | Use |
|---|---|
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.
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:
| Variable | Holds |
|---|---|
mbo | the formula’s record |
params | the arguments, as a Java list of BigDecimal |
ctx | the function itself |
exp | the 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 type | Result |
|---|---|
| Integer, Long, Short, BigInteger, Double | the number |
| Date | its milliseconds |
| String | its hash code |
| Float, Boolean, anything else | None |
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. Writeinvokescript("CREATEMETERS"). - No access checks.
newmboandsetvaluetomboadd 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#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
| The mail call in MXERR | sendEmail | sendEMail; the other spelling was missing on our test system |
| The MXERR test | ekey="something" | an assignment; the script cannot be saved |
| MXERR variables | egroup, ekey, eparams | also emsg, the formatted message |
| Role functions | declare one of the two | evalToPerson alone covers both paths |
| Formula results | not listed | only number types and dates; Float and Boolean give None |
| An MBR library call | invokescript("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:
- Automation scripts in the IBM Maximo Manage documentation.
- All about Maximo scripting, IBM’s scripting guide on GitHub.
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.
