Maximo automation scripts became more and more powerful during the last years so we heavy rely on these capabilities to extend Maximo features and fulfill customer needs. When the amount of script code grows, it’s easy to end up into some sort of spaghetti code so you need a practical way split the code into reusable pieces. Modular programming and structured programming was adopted in software development since the late 1960s so we MUST definitely embed this technique in our developer’s toolset.
Python function
The simplest way of define a reusable piece of code in python is to define a function. In this example we have defined the function getDescription that returns a concatenation of fields to be set in the description field of the current mbo.
def getDescription():
d = mbo.getString("ASSETNUM")
d += "-" + mbo.getString("ASSETTYPE")
d += "-" + mbo.getString("SERIALNUM")
return d
desc = getDescription()
mbo.setValue("DESCRIPTION", desc)
The limitation of this technique is that the getDescription function can only be invoked from the same script. This limits our capabilities of defining a common set of library functions that can be reused from other scrips.
The service.invokeScript method
The classic way for invoking a script from another script is is to use the implicit service variable that provides the invokeScript function. In the example below, we have defined the CX_TEST and CX_TESTLIB scripts.
# CX_TESTLIB
d = mbo.getString("ASSETNUM")
d += "-" + mbo.getString("ASSETTYPE")
d += "-" + mbo.getString("SERIALNUM")
# CX_TEST
from java.util import HashMap
map = HashMap()
map.put("mbo", mbo)
map = service.invokeScript("CX_TESTLIB")
desc = map.get("d")
mbo.setValue("DESCRIPTION", desc)
The CX_TEST script invokes the CX_TESTLIB passing the current mbo and retrieving the returned value.
This technique has variuos limitations and drawbacks:
- Is very verbose and makes the code hard to read
- does not allow to natively define multiple funtions in the CX_TESTLIB script (yes you can pass an additional argument and use it as a fuction name but it’s very cumbersome)
The “Allow Invoking Script Functions” magic checkbox
Now create a another automation script called CX_TEST2 and ensure to select the “Allow Invoking Script Functions” checkbox while creating it. You cannot change this setting after the script is created.

The two sample scripts are now easier to read and understand.
# CX_TEST2
def getDescription(service, mbo):
d = mbo.getString("ASSETNUM")
d += "-" + mbo.getString("ASSETTYPE")
d += "-" + mbo.getString("SERIALNUM")
return d
# CX_TEST
desc = service.invokeScript("CS_TESTLIB2", "getDescription", [service, mbo])
mbo.setValue("DESCRIPTION", desc)
With this technique you can invoke the getDescription function (defined in a separate script) pass the arguments and get the returned value in one line of code. The library script can contain multiple functions so you can group the most frequently used code snippets in one script.
You are now ready for modular programming with Maximo automation scripts!
