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=0reloads 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 anmboormboset.onadd,onupdate,ondelete: only with anmbo.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 useservice.getScriptName().userInfo: missing in object, attribute, action and condition launch points; usembo.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:
errorgroupanderrorkey, withparams.errorgrpdoes nothing. - Warning:
warngroupandwarnkey, withwarnparamsas a list. - Condition:
evalresult, True or False on every path. - REST:
responseBody, text or bytes; an action also takes a record or a set. OfresponseHeaders, onlycontent-typeis used. - Retrieve list:
listWhere,listOrder,relationObjectwithrelationWhere,srcKeys(lookup object) withtargetKeys(current object),domainid. - Attribute init:
thisvalue, andthisvalue_required,_readonly,_hidden. - MXERR scripts:
mxerrormsgadds 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.ATTRfollows a relationship, and a trailing*gives an array. - Flags:
ATTR@readonly,@required,@hiddenread a flag, and as OUT or INOUT set it.@modified,@initial,@previousand@internalonly read. - Companions:
var_required,var_readonly,var_hidden. Attribute launch points addvar_initial(a value object),var_previous(named after the field) andvar_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 transactionservice.isLoggingEnabled()does not exist.- The function form of
invokeScriptneeds “Allow Invoking Script Functions”. Inside the function,serviceandmboare undefined. Names that start withLIB.,OSIN.orOSOUT.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, andcount()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.getMboSetopens its own transaction. Close such a set withcleanup()infinally.- 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>.NEWafter every add.<OBJECT>.SAVEbefore 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.OUTand.IN. - Your own names: no dot, for example
WORKORDER_SAVE_SETCREW. - More: article 10 and article 18.
REST scripts#
GETorPOST /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
authappandauthsigoptionon the script. ?action=<NAME>on a record runs the action’s script, by conventionOSACTION.<OS>.<NAME>; sendx-method-override: PATCHto get the record. A literalallowget = 0blocks GET.- More: article 22, article 23 and article 24.
System properties#
mxe.script.deactivateall=1switches every script off.mxe.script.autocleanup=truecleans up the sets a script left in its variables.mxe.script.jsfuncwrap=1wraps JavaScript in a function, sovarnames become local.mxe.attachmentstorage: a class, orscript:<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. printoutput 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()))- More: article 14.
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#
errorgrpiserrorgroup.isLoggingEnabled()is missing.yncuserinput()takes no arguments.org.jdomcannot be imported: useorg.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.
