Object relation scripts

An object relation script is an automation script without a launch point. This script is used to define smart relations, which are relations that use conditional SQL in the where clause.

The following scenarios show when an object relation script can be useful:

  • To break a complex SQL where clause into simpler conditional blocks, which might improve performance in certain cases.
  • To handle a database fetch that depends on the state of the application or on user input. These cases are not cases for parameterized SQL, but cases where the structure of the SQL changes drastically depending on the conditions.

When the Maximo® business object (MBO) framework evaluates a relationship, such as mbo.getMboSet("relation"), it determines whether the relation where clause is implemented by an automation script based on the registration of the relation in the MAXRELATIONSHIP table. The relation where clause needs to contain the expression script:script_name for the framework to run the script.

The following table shows the implicit variables for object relation scripts.
Table 1. Implicit variables for object relation scripts
Variable name Description
mbo The source MBO record that is input to the script.
mboset The response MboSet instance that is the target or the relation. The script is expected to create this MboSet.
The following script is an example of an object relation script.
if mbo.isNull("priority")==False:
 mboset = mbo.getMboSet("openwo")
else:
 mboset = mbo.getMboSet("allwo")

Another advanced use case is to pass certain contextual information from an application to the Maximo business object by using an API call. The following call is a sample REST call.

GET /api/os/mxapiwo?oslc.select=rel.asset{assetnum,rel.assetmeter{lastreading}}&ctx=param1=value1

For example, if you want to introduce smart filtering on the assetmeter relation, you can replace this relation in the URL with a custom one.

GET /api/os/mxapiwo?oslc.select=rel.asset{assetnum,rel.custassetmeter{lastreading}}&ctx=param1=value1

Now, custassetmeter can be backed by a relation script that can use the information that is passed in the ctx from the script and can generate a smart where clause.

The following script is an example of an object relation script.
from psdi.iface.mic import IntegrationContext
if IntegrationContext.getCurrentContext() is not None and IntegrationContext.getCurrentContext().isAPICall(): 
  val1 = IntegrationContext.getCurrentContext().getParameter("param1")
  #create a filter clause based on the val1 and set the mboset
else:
  mboset = mbo.getMboSet("assetmeter")