Formula functions

Formulas provide an expression library to calculate numeric values from Maximo business objects (MBOs). The framework provides many standard functions. The scripting framework provides a way to create custom functions to extend the library of built-in functions. The following example shows the setup steps to add the standard deviation function using scripting.

Write the formula script code. The following example uses Python. This script uses the Apache math library to calculate the standard deviation.
from org.apache.commons.math3.stat.descriptive import DescriptiveStatistics
from java.lang import Math

relation = ctx.getExpression().getCalculatedValue(params[0])
attr = ctx.getExpression().getCalculatedValue(params[1])
dstats = DescriptiveStatistics()
workOrders = mbo.getMboSet(relation)
wo = workOrders.moveFirst()
while wo is not None:
  cost = wo.getDouble(attr)
  dstats.addValue(cost)
  wo = workOrders.moveNext()

std = dstats.getStandardDeviation()
service.log(str(std))
evalresult = std
The following list of implicit variables is supported by this script point.
Table 1.
Variable Purpose
exp An instance of com.ibm.tivoli.maximo.expression.Expression which is a handle to the parsed formula expression instance.
ctx An instance of the com.ibm.tivoli.maximo.expression.ScriptFunction function.
mbo The MBO in context for the formula.
params The input parameters.

In the Database Configuration application, add a new formula function with the implementation type of script and the class name or script name as the name of the script in uppercase.

Add or modify the formula for an object or attribute. The formula for this sample is on the Asset object.

A way to test this formula would be to make the following REST API call:
GET /oslc/os/mxapiasset?lean=1&oslc.select=assetnum,siteid,exp.assetwocoststd&oslc.where=assetnum="11430"
where exp.assetwocoststd is the formula name.