Overview
Application Scenario
Abundant built-in functions are provided in FineBI, which are sufficient to meet your normal needs in template design. However, in some special fields, you may require special functions. In this case, you can define custom functions in FineBI according to your business needs. However, these functions must comply with FineBI function definition rules.

Applied Scope
Only extracted data version is supported.
Custom aggregation functions are not supported, such as aggregate functions and quick calculation functions.
Definition Rule
FineBI function definition rules: Functionname(Para,Para,...), where Functionname is the function name and Para is the parameter.
In FineBI, each function is defined as a class, which must help to realize the Function as an interface. When performing the calculation, the class that performs the function is obtained through reflection based on the function name, and then its run(Object[] args) method is called.
Take the SUM function as an example. The SUM class is used to perform calculations of the SUM function, and the class inherits the AbstractFunction class, which implements the Function interface.
When performing the calculation, the function first obtains the class that performs the function based on the function name. For example, the function SUM(2,4,true) first obtains the SUM class based on the function name, and then call the run(Object[] args) method of the SUM class. The args array contains the parameters of the SUM function, and the parameters can be retrieved from the args array for calculation. For example, the execution result is as follows: SUM(2,4,true)=2+4+1=7.
Code used by the SUM function:
package com.fr.report.script;
import com.fr.general.FArray;
import com.fr.script.AbstractFunction;
public class CSUM extends AbstractFunction {
public Object run(Object[] args) {
double result = 0;
for (int i = 0; i < args.length; i++) {
if (args[i] == null) {
continue;
}
result += parseObject(args[i]);
}
return result;
}
private double parseObject(Object obj) {
if (obj instanceof Number) {
return ((Number) obj).doubleValue();
} else if (obj instanceof Boolean) {
return ((Boolean) obj).booleanValue() ? 1 : 0;
} else if (obj instanceof FArray) {
FArray array = (FArray) obj;
double sum = 0;
for (int i = 0; i < array.length(); i++) {
sum += parseObject(array.elementAt(i));
}
return sum;
} else if (obj != null) {
try {
return Double.parseDouble(obj.toString());
} catch (NumberFormatException exp) {
return 0;
}
}
return 0;
}
}
Compiling Environment Preparation
For details, see Compiling a Java Program.
Example
Take a simple custom function as an example to explain the use of the custom function.
Define a function called StringCat, which is used to combine all the parameters into a character string.
For details, see: Custom Function for Combination as Character String.
Notes
1. The custom function name is based on the class file name.
2. The custom function file name only supports English, including uppercase, lowercase, and mixed case input.
3. The added functions are displayed in Other Functions.
4. Mixed case input is currently not supported.