The previous article showed the variables that you declare. This one shows the others. Keep it open while you write a script: most surprises with implicit variables come from expecting one that this kind of launch point never gets.
We checked IBM’s two tables of implicit variables against the behaviour of Manage in the MAS 9.2 series. Where a table and Manage disagree, this page follows Manage. The variables of integration, REST and the other special script types belong to their own articles later in this series.
What every run gets#
Two variables are there on almost every run:
service, the helper object for errors, logging and calls to other scripts. Each run gets a new one.scriptName, the name of the running script. Launch points, library calls and cron tasks set it. A script called through the REST API does not get it: on our test system, such a run failed with a NameError.service.getScriptName()gives the name in every run.
Every launch point adds launchPoint, its own name. And when the run has a record to work on,
Manage adds the record and a few facts about it:
| Variable | What it holds |
|---|---|
mbo | the record the script works on |
mboname | the name of its object, for example WORKORDER |
app | the application that opened the record; empty when no application did |
user | the user ID of the session; a script cannot change it |
interactive | true in a user session, false in the background |
onadd | true for a new record |
onupdate | true for an existing record that will be saved |
ondelete | true for a record that will be deleted |
One variable is missing here although IBM’s table lists it for all launch points: userInfo.
Object, attribute, action and condition launch points do not get it. In those scripts, use
mbo.getUserInfo().
Object launch points#
An object launch point gets the list above for the init, app validate and save events. Its events differ in one point: whether there is a record at all.
- Init, app validate, add, update and delete get
mbo. There is nombosetvariable. Reach the set throughmbo.getThisMboSet(). - Allow create (“can add”) gets only
mboset, the set the new record would join. There is nombo, and so noonadd,onupdateorondeleteeither. - The setup and execute events of a non-persistent object get
mboset. In setup,mbois empty.
Attribute launch points#
An attribute launch point gets the common list, with mbo as the record that owns the field. It
adds the field itself:
| Variable | What it holds |
|---|---|
mbovalue | the field’s value object, with methods such as getString() |
mboattr | the field name, in lower case |
the field name in lower case, for example status | the current value |
status_previous | the value before the change |
status_initial | the value when the record was loaded |
The last two names come from the field, whatever your own variables are called. A variable
wostatus bound to STATUS gets no wostatus_previous; the previous value is in
status_previous.
The events of an attribute launch point add their own variables:
- Retrieve list gets
lookupnameandapplink. The script answers withlistWhere,listOrder,domainid,relationObjectandrelationWhere, and withsrcKeysandtargetKeys. Article 9 of this series covers lookups. - Initialize value reads
thisvalueafter the run and puts it into the field. - Initialize access restriction reads
thisvalue_required,thisvalue_readonlyandthisvalue_hiddenafter the run. Only true and false count there.
Action launch points#
An action launch point is called by a workflow, an escalation or a button. It gets the common list,
with mbo as the record the action works on, and adds:
scriptHome, the same record asmbo.action, the name of the action.params, the parameters of the action call.wfinstance, the workflow instance, only when a workflow started the action.
params has a second use: the parameters of an error message, see below. In an action script it
already holds the action’s parameters when the script starts, so set it to your own list before you
raise an error through errorkey.
Custom condition launch points#
A custom condition gets the common list and one more variable: evalresult. It starts empty,
and the script must set it to true or false. A condition script that leaves it empty fails. Manage
has no default of false.
Cron task scripts#
A script started by the script cron task has no record, so there is no mbo. It gets:
arg, the text of the cron task’s SCRIPTARG parameter. Convert it yourself, for example withint(arg).runAsUserInfo, the user the cron task runs as. Note the capital A.instanceName, the cron task and its instance, asCRONTASKNAME.INSTANCENAME.scriptNameandservice.
An error in the script is logged, and the cron task keeps running.
Variables that come with a declared variable#
Each declared variable that is bound to a field brings a few more, named after the variable with a
suffix. For a variable siteid:
| Variable | What it holds | Can the script change it? |
|---|---|---|
siteid_required | the required flag of the field | yes, if siteid is OUT or INOUT |
siteid_readonly | the read-only flag | yes, if siteid is OUT or INOUT |
siteid_hidden | the hidden flag | yes, if siteid is OUT or INOUT |
siteid_modified | whether the field was changed | no |
siteid_initial | the value when the record was loaded | no |
siteid_internal | the internal value, for a synonym domain only | no |
Four details matter in practice:
- The flags change only for OUT and INOUT. For an IN variable,
siteid_readonly = Truehas no effect. After save and after commit, nothing is written back at all. - Hidden also means read-only. Setting
siteid_hidden = Truealso makes the field read-only, and setting it to false also clears read-only. siteid_initialis no plain value. It holds a Maximo value object, so a comparison with a text is always false. Usestr(siteid_initial).- These variables exist only for field bindings. A variable bound to a MAXVAR, a system property or a fixed value gets none.
What Manage reads after the run#
Some variables flow the other way. The script sets them, and Manage reads them when the script has ended.
errorgroup,errorkeyandparamsraise an error with a message from the message table, when both group and key are set.service.error(group, key)does the same at once and is the better choice.warngroup,warnkeyandwarnparamsadd a warning to the record’s set, and the run continues. Neither IBM page names them. Passwarnparamsas a list: a Java string array is replaced byparams, which we saw on our test system.evalresult, in a custom condition.- The retrieve list and initialize variables above, in an attribute launch point.
Thirteen names are reserved. The Automation Scripts application refuses a declared variable
called app, errorgroup, errorkey, evalresult, params, user, launchPoint,
scriptName, mboname, mbo, onadd, onupdate or ondelete. Other implicit names, such as
service or interactive, are not reserved. Avoid them anyway, because a declared variable of the
same name hides the implicit one.
What IBM’s tables get wrong#
Six rows of IBM’s two tables are wrong for the 9.2 series:
| Variable | IBM’s table | What Manage does |
|---|---|---|
userInfo | all launch points | none of the four launch point kinds |
mbovalue | a user info object | the field’s value object |
onupdate | the record is inserted or created | the record exists and will be saved |
srcKeys, targetKeys | source is the current record | swapped: targetKeys name the fields of the current record |
var_initial | a value of the field’s type | a Maximo value object |
var_previous | named after the declared variable | named after the field, in lower case |
The cron task page also writes runasUserInfo with a small a, and the async job page names a
variable where that is called whereclause. Article 33 of this series collects the corrections
that matter most.
What comes next#
Article 5 covers the Variables tab: bindings, flags, and the traps in between.
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 inventory of what the script engine does without documentation 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.
