↓ Skip to main content
An ink and watercolour drawing of a cream card pinned with an orange pushpin to a wooden board above a workbench. The card holds twelve boxes with small symbols: a key, a gear, a bell, a flag, a magnifying glass, a lock, a clock, a book, a hammer, a light bulb, an envelope and a check mark. A pencil cup, a plant, a vice and a teal toolbox stand on the bench.

The Automation Script Quick Reference Card

Maximo Automation Scripts - This article is part of a series.
Part 35: This Article
This page holds the facts of the whole series that a script developer needs while writing: the variables, the bindings, the service object, transactions, the names Manage runs, REST, properties, logging and JavaScript. Every line was checked against the behaviour of Manage in the MAS 9.2 series, and each section links to the article with the details.

This article closes the series. It is meant to stay open next to the editor.

Engines
#

  • Jython 2.7.4 and Nashorn ship with Manage in the 9.2 series. Out of the box there is no Groovy, JRuby or Rhino.
  • A script is compiled once, when the script cache loads it, and then runs from the cache.
  • Saving a script reloads only that script. mxe.script.reloadperscript=0 reloads the whole cache.
  • More: article 2.

Variables a script gets
#

  • mbo: the record. mboset: only for can add and the setup of non-persistent objects.
  • app, user, interactive, mboname: when there is an mbo or mboset.
  • onadd, onupdate, ondelete: only with an mbo.
  • mbovalue: the field’s value object, in attribute launch points.
  • launchPoint, service: in every launch point. scriptName: in launch points, library calls and cron tasks; in REST runs use service.getScriptName().
  • userInfo: missing in object, attribute, action and condition launch points; use mbo.getUserInfo().
  • Action: action, scriptHome, wfinstance (from workflow only).
  • Cron task: runAsUserInfo, instanceName, arg.
  • Async job: jobqnum, whereclause, userInfo, mboname.
  • REST script: request, requestBody (missing on GET), httpMethod, userInfo, responseHeaders.
  • Integration exits: irData, erData, ifaceName, ifaceType, extSystem, messageType, osName. Object structure scripts: ctx.
  • MXERR scripts: egroup, ekey, eparams, emsg.
  • More: article 4.

Variables a script sets
#

  • Error: errorgroup and errorkey, with params. errorgrp does nothing.
  • Warning: warngroup and warnkey, with warnparams as a list.
  • Condition: evalresult, True or False on every path.
  • REST: responseBody, text or bytes; an action also takes a record or a set. Of responseHeaders, only content-type is used.
  • Retrieve list: listWhere, listOrder, relationObject with relationWhere, srcKeys (lookup object) with targetKeys (current object), domainid.
  • Attribute init: thisvalue, and thisvalue_required, _readonly, _hidden.
  • MXERR scripts: mxerrormsg adds text to the message.
  • More: article 12 and article 9.

Bindings
#

  • Types: LITERAL, SYSPROP, MAXVAR, ATTRIBUTE. Directions: IN, OUT, INOUT.
  • Values are copied in before the run and back after it. After save and after commit copy nothing back.
  • Paths: REL.ATTR follows a relationship, and a trailing * gives an array.
  • Flags: ATTR@readonly, @required, @hidden read a flag, and as OUT or INOUT set it. @modified, @initial, @previous and @internal only read.
  • Companions: var_required, var_readonly, var_hidden. Attribute launch points add var_initial (a value object), var_previous (named after the field) and var_modified.
  • More: article 5.

The service object
#

service.error("grp", "key")           # or (grp, key, params)
service.setWarning("grp", "key", p)   # needs an mbo
service.log_info("text")              # log, log_debug ... log_fatal, logError
service.yncerror("grp", "key")        # or (grp, key, params)
x = service.yncuserinput()            # no arguments
service.invokeScript("LIBNAME", ctx)  # ctx: java.util.HashMap
r = service.invokeScript("LIB.X", "fn", [a, b])
s = service.getMboSet("ASSET", ui)    # its own transaction
  • service.isLoggingEnabled() does not exist.
  • The function form of invokeScript needs “Allow Invoking Script Functions”. Inside the function, service and mbo are undefined. Names that start with LIB., OSIN. or OSOUT. get the flag on their first save.
  • More: article 11 and article 13.

MBO idioms
#

from psdi.mbo import MboConstants

if mbo.getMboSet("WORKLOG").notExist():   # one EXISTS query, no record built
    service.error("custom", "noworklog")
if mbo.isModified("PRIORITY"):            # changed in this transaction
    pass
mbo.setValue("DESCRIPTION", "x", MboConstants.NOACCESSCHECK)
  • Prefer notExist(). isEmpty() builds the first record, and count() queries until every row is read.
  • More: article 16.

Transactions
#

lines = mbo.getMboSet("POLINE")                         # same transaction, saved with mbo
dc = mbo.getMboSet("$NEWDC", "PLUSDESTCONTROL", "1=2")  # same transaction; unique name
  • Never save a set opened from mbo. Manage saves it with the record.
  • A second call with the same name and another where clause resets a named set and drops its new records, without an error.
  • service.getMboSet opens its own transaction. Close such a set with cleanup() in finally.
  • More: article 15 and article 17.

Launch points and events
#

  • Object: initialize, add, update, delete, after save, after commit, app validate, can add, can delete. Attribute: initialize access restriction, initialize value, validate, run action, retrieve list.
  • Several scripts on one event run in no fixed order, and a number in the name changes nothing.
  • An attribute launch point runs on every value set: in the screen, in imports, in script loops.
  • After commit: an error is logged and dropped. Change no records in after save or after commit.
  • More: article 6, article 7 and article 29.

Names Manage runs
#

  • <OBJECT>.NEW after every add. <OBJECT>.SAVE before every save, with no launch point; with a save launch point it runs twice.
  • <OBJECT>.DUPLICATE, <OBJECT>.AFTERDUPLICATE; MXERR.<GROUP>.<KEY>; MAXROLE.<ROLE>.
  • OSIN.<OS>, OSOUT.<OS>, OSACTION.<OS>.<ACTION>, OSQUERY.<OS>.<QUERY>.
  • PUBLISH.<CHANNEL>.EVENTFILTER, .EXTEXIT.OUT, .USEREXIT.OUT.BEFORE, .USEREXIT.OUT.AFTER.
  • Enterprise service: <MSGTYPE>.<SERVICE>.EXTEXIT.IN. Invoke channel: INVOKE.<CHANNEL>.EXTEXIT.OUT and .IN.
  • Your own names: no dot, for example WORKORDER_SAVE_SETCREW.
  • More: article 10 and article 18.

REST scripts
#

  • GET or POST /maximo/api/script/<NAME> runs the script. An inactive script answers HTTP 200 with an empty body.
  • Protection needs both values: application and option on the route, or both variables authapp and authsigoption on the script.
  • ?action=<NAME> on a record runs the action’s script, by convention OSACTION.<OS>.<NAME>; send x-method-override: PATCH to get the record. A literal allowget = 0 blocks GET.
  • More: article 22, article 23 and article 24.

System properties
#

  • mxe.script.deactivateall=1 switches every script off.
  • mxe.script.autocleanup=true cleans up the sets a script left in its variables.
  • mxe.script.jsfuncwrap=1 wraps JavaScript in a function, so var names become local.
  • mxe.attachmentstorage: a class, or script:<NAME> for a store script.
  • More: article 34.

Logging
#

  • Each script logs to maximo.script.<SCRIPTNAME>, and every run sets that logger to the script’s Log Level field.
  • At WARN or ERROR, service.log() writes nothing.
  • print output appears after the script ends, and is lost if it fails.
log = service.getLogger("maximo.script." + service.getScriptName())
if log.isDebugEnabled():
    service.log_debug("rows " + str(mboset.count()))

JavaScript
#

var MXServer = Java.type("psdi.server.MXServer");
responseBody = JSON.stringify({ ok: true });   // a global, at the top level
  • Write ES5. Missing at run time: Map, Set, Symbol, Promise, includes, startsWith, find, Object.assign.
  • Never write "use strict".
  • More: article 2 and article 32.

Checked pitfalls
#

  • errorgrp is errorgroup. isLoggingEnabled() is missing. yncuserinput() takes no arguments.
  • org.jdom cannot be imported: use org.jdom2.
  • In Jython, catch Java errors as java.lang.Throwable.
  • The launch point conflict warning BMXAA10022W never fires.
  • More: article 33 and article 31.

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