The previous article covered four of the five attribute events. This one covers the fifth. We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series. Where the two disagree, this page follows Manage.
Who asks for the list#
A retrieve list launch point attaches a list provider to its field. The script runs only when something asks that field for its list:
- A lookup in the user interface, when the user opens it.
- The REST API, with a
getlist~request for the field, for examplegetlist~address5. - Maximo Mobile, which asks for lookups through the same REST request on an empty record.
So one script serves all three. Manage keeps an empty record on each set for exactly this case, and the launch point attaches to it as well. Three cases are left out: internal objects, MAXUSER, and multitenant systems. There the empty record gets no script.
The screen side of a lookup, the lookup definition that the application shows, is application configuration. This article is about the script.
What the script gets and what it sets#
The script gets the record as mbo, the field under its own name in lower case, and two lookup
variables. Everything else is output: Manage reads it after the run.
| Variable | Direction | Meaning |
|---|---|---|
lookupname | in | the current lookup name of the field |
applink | in | the application the lookup links to |
listMboSet | out | the set of records the lookup offers |
listWhere | out | an extra where clause for the list |
listOrder | out | the order of the list |
domainid | out | a domain that provides the list |
relationObject, relationWhere | out, as a pair | an object and a where clause that provide the list |
srcKeys, targetKeys | out, as a pair | which fields of the chosen record fill which fields of this record |
listErrorGroup, listErrorKey | out, as a pair | the message for a typed value that is not in the list |
When the script sets no listMboSet, the field’s normal list comes back.
The keys work in pairs and in order. srcKeys name fields of the record that the user picks in
the lookup. targetKeys name the fields of the current record that receive them. The first source
fills the first target, the second the second, and so on. IBM’s table of implicit variables
describes the two the other way round.
When a typed value is checked#
A user can also type a value into the field without opening the lookup. Whether Manage checks that value against the list depends on what the script set:
domainid, or the pairrelationObjectandrelationWhere: Manage checks a typed value against that list. A value that is not in it is refused with the message fromlistErrorGroupandlistErrorKey, or with a general “not valid” message when the script set none.- Only
listMboSet: the lookup offers the script’s records, and a typed value is not checked at all. Any value goes in.
So when the field must only hold values from the list, give the script a domain or a relationship, or add a validate launch point for the field.
A working example#
A lookup on the field ADDRESS5 of an address that offers countries, and fills ADDRESS5 with the country’s name. In Jython:
from psdi.server import MXServer
listMboSet = MXServer.getMXServer().getMboSet("COUNTRY", mbo.getUserInfo())
srcKeys = ["NAME"]
targetKeys = ["ADDRESS5"]Two details make this work, and IBM’s own example gets both wrong:
- The user comes from
mbo. An attribute launch point has nouserInfovariable. IBM’s example passesuserInfo, which in its JavaScript version stops the script with a ReferenceError. Usembo.getUserInfo(). - The keys must be a Java list or a Java string array. A Jython list is a Java list when Manage reads it. A JavaScript array is neither, as our tests in article 2 show. In JavaScript, convert both:
var MXServer = Java.type("psdi.server.MXServer");
listMboSet = MXServer.getMXServer().getMboSet("COUNTRY", mbo.getUserInfo());
srcKeys = Java.to(["NAME"], "java.lang.String[]");
targetKeys = Java.to(["ADDRESS5"], "java.lang.String[]");Choosing the lookup name from a script#
A field can switch between lookups depending on the record. The initialize value event of an
attribute launch point can set lookupname. A non-empty value becomes the field’s lookup name for
that record. IBM’s example picks a numeric or a text domain lookup depending on the asset type.
The retrieve list script then receives that name in lookupname. It must back the choice up: the
example sets domainid there. Set in any event other than retrieve list, domainid does nothing.
What IBM’s pages get wrong here#
| Topic | IBM’s pages | What Manage does |
|---|---|---|
userInfo in the lookup example | passed to the set | no such variable in an attribute launch point; use mbo.getUserInfo() |
| Keys in the JavaScript example | plain JavaScript arrays | Manage needs a Java list or a Java string array; use Java.to |
srcKeys, targetKeys | srcKeys name fields of the current record | srcKeys name fields of the chosen record, targetKeys those of the current record |
Article 33 of this series collects the corrections that matter most.
What comes next#
Article 10 covers the scripts that Manage runs by name, with no launch point at all.
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.
