Creating lookups by using scripts

You can create lookups by using the retrieve list option of the attribute launch point.

You must associate the script with the Maximo® business object (MBO) attribute on which you want the lookup to happen. Although writing the script is enough for lookups to work from REST APIs, that is, GET getlist~attribute, it is not enough for lookups to work in the user interface.

For applications that are not Graphite-based, you are required to make an entry in the lookups.xml for the lookup dialog. You also need to associate the lookup name to the MBO attribute in the corresponding presentation XML. In the following example, you write a lookup for the address5 attribute in the address MBO for the multisite application. The address5 attribute maps to a country name by using the country code. For example, you want to use some of the external REST APIs that provide the list of countries. A number of APIs exist that can be used. However, for this example, a simple HTTP GET call that uses basic authentication of a user name and password and a response is used:
{"USA" : "United States Of America", "CAN":"Canada", "GBR": "United Kingdom"}
You must then write the retrieve list script. The following example is in Nashorn JavaScript and uses some of the JSON parsing capabilities of Nashorn JavaScript.
importPackage(java.util)
importPackage(Packages.psdi.server)

var jsonResp = service.httpget("..url..","..userid..","..password..");
var countries = JSON.parse(jsonResp);
var countriesSet = MXServer.getMXServer().getMboSet("COUNTRY", userInfo);
for(var cnt in countries)
{
    var cntMbo = countriesSet.add();

The implicit variable listMboSet holds the MBOSET that is used in the lookup. The target MBO attribute where the value is set has a different name, address5, from the source attribute name, which is the name in the COUNTRY MBO. Therefore, you must use the implicit variables srcKeys and targetKeys to indicate where to set the selected value.