Formula functions
Maximo Formulas provide an Excel-like expression library to calculate numeric values from MBOs. The framework provides many standard functions in the default version. Scripting framework provides customers with 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 (python sample). This leverages the apache math library to calculate the standard deviation.
from org.apache.commons.math3.stat.descriptive import DescriptiveStatisticsfrom java.lang import Mathrelation = 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:
The following list of implicit variables is supported by this script point:
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. |
- Add a new Formula function with the implementation type as “script” and the Class name or script name as the name of the script (in uppercase).
- Add or modify Object or Attribute Formula. The formula for this sample is on Asset object.
A way to test this 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"
The following graphic shows a sample result: