Maximo Scripting – Library Scripts

This post is an excerpt from the Maximo 76 Scripting Features guide.

Library scripts are good for encapsulating some re-usable logic. In Maximo 7.6, we can write library scripts as just simple scripts. We can write these scripts in any language and then call from another language. Lets make a library script for making HTTP GET calls. We can make that using a py script like below.

from psdi.iface.router import HTTPHandler
from java.util import HashMap
from java.util import String
handler = HTTPHandler()
map = HashMap()
map.put("URL", url)
map.put("HTTPMETHOD", "GET")
responseBytes = handler.invoke(map,None)
response = String(responseBytes, "utf-8")

Here the script is expecting a variable called “url” to be passed into the script from the invoking script. The response is set to the “response” variable, which can be used by the calling script to get the response data as a string.

A sample script (js) code that can leverage this library script is shown below

importPackage(java.util)
importPackage(Packages.psdi.server)
var ctx = new HashMap();
ctx.put("url", "http://localhost:7001/maximo/oslc/script/countryapi?_lid=wilson&_lpwd=wilson");
service.invokeScript("LIB_HTTPCLIENT", ctx);
var jsonResp = ctx.get("response");
var countries = JSON.parse(jsonResp);

Note how it creates the ctx and then passes the “url” to it and then uses service.invokeScript api to invoke the library http script (named LIB_HTTPCLIENT). The script also gets the response from the “response” variable and then uses the JSON.parse(..) api to parse that data to a json object for further processing.

Maximo Scripting – Library Scripts

One thought on “Maximo Scripting – Library Scripts

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top