Function libraries
When uploading rules files, TMS offers the functionality to declare those as libraries. The following example shows a function which just calculates the average of 2 number:
package com.peaksolution.tms.drools.activity.test
import java.math.BigDecimal
function BigDecimal calcAverage(Long pMin, Long pMax)
{
return BigDecimal.valueOf((pMin + pMax) / 2);
}
When registering the file in TMS it is important to activate the library checkbox:

Declaring code snippet as library
This function can than be used in another file:
package com.peaksolution.tms.drools.activity.test
import com.peaksolution.rules.model.Activity;
global Validator validator;
global SessionContext sessionContext;
rule "Set average temperature"
when
$attrTempMin: Attribute(name == "TEMP_MIN", getValueAsLong() != null)
$attrTempMax: Attribute(name == "TEMP_MAX", getValueAsLong() != null)
$attrTempAvg: Attribute(name == "TEMP_AVG")
then
$at-trTempAvg.setValueAsDecimal(calcAverage($attrTempMin.getValueAsLong(),
$attrTemp-Max.getValueAsLong()));
end
info
To use a function of a rule set file both files, the file with the function and the file using the function need to have the same package declaration!