↓ Skip to main content
An ink and watercolour drawing of an orange wooden card index cabinet on a workbench, with three closed drawers and teal knobs. On top, an open tray holds a row of blank index cards, and one card stands higher than all the others.

Lookups From a Script: The Retrieve List Event

Maximo Automation Scripts - This article is part of a series.
Part 9: This Article
The retrieve list event lets a script decide what a lookup offers for one field, and which fields the user’s choice fills. It is the most powerful attribute event and the least documented one. This article shows what the script gets, what it sets, and the one case in which a typed value is never checked.

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 example getlist~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.

VariableDirectionMeaning
lookupnameinthe current lookup name of the field
applinkinthe application the lookup links to
listMboSetoutthe set of records the lookup offers
listWhereoutan extra where clause for the list
listOrderoutthe order of the list
domainidouta domain that provides the list
relationObject, relationWhereout, as a pairan object and a where clause that provide the list
srcKeys, targetKeysout, as a pairwhich fields of the chosen record fill which fields of this record
listErrorGroup, listErrorKeyout, as a pairthe 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 pair relationObject and relationWhere: Manage checks a typed value against that list. A value that is not in it is refused with the message from listErrorGroup and listErrorKey, 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.
What the retrieve list script decides What the retrieve list script decides
What the retrieve list script decides

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 no userInfo variable. IBM’s example passes userInfo, which in its JavaScript version stops the script with a ReferenceError. Use mbo.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
#

TopicIBM’s pagesWhat Manage does
userInfo in the lookup examplepassed to the setno such variable in an attribute launch point; use mbo.getUserInfo()
Keys in the JavaScript exampleplain JavaScript arraysManage needs a Java list or a Java string array; use Java.to
srcKeys, targetKeyssrcKeys name fields of the current recordsrcKeys 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:

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.

Maximo Automation Scripts - This article is part of a series.
Part 9: This Article