You can use the StringCat function in FineBI to combine strings, for example, to combine Contract ID and Contract Payment Type from Contract Information together as a single field, as shown in the following figure.
Since the Function interface is implemented in the AbstractFunction class, the StringCat function can directly inherit the AbstractFunction class.
When you use the function StringCat(Para,Para,Para…), the system obtains the StringCat class that performs the operation based on the function name, passes parameters into the args object array in the class, and execute the run function of the class. In the run function, the input parameters are combined as a character string, and returns the final combined string.
Function Description
The StringCat function is used to combine all parameters into a string.
The StringCat function is used in the form of StringCat(Para,Para,Para...), where Para is a parameter of the function, and the number of parameters is unlimited.
Writing the Java File
Write StringCat.java. The function code is as follows:
package com.fr.function;import com.fr.script.AbstractFunction;public class StringCat extends AbstractFunction {public Object run(Object[] args) {String result = "";Object para;for (int i = 0; i < args.length; i++) {para = args[i];result += para.toString();}return result;}}
Preparing the Compilation Environment
For details, see Compiling Java Program.
Generating a CLASS File
Compile StringCat.java to generate the StringCat.class file.
Importing a CLASS File
Place the compiled StringCat.class file into FineBI installation directory\webapps\webroot\WEB-INF\classes\com\fr\function, as shown in the following figure.
After restarting FineBI, you can use the custom function directly. The usage of the custom function is the same as that of the built-in function.
For example, when adding calculated indicators, you can see the previously defined function Stringcat in Other Function. Click the function to add it to the formula, as shown in the following figure.
To combine Contract ID and Contract Payment Type from Contract Information into a single field, enter the formula: StringCat(Contract ID," ",Contract Payment Type), as shown in the following figure.
For details, see section "Expected Effect".
Refer to sections "Writing the Java File", "Compilation Environment Preparation", and "Generating a class File" to compile and generate a StringCat.class file.
Place the StringCat.class file in the directory FineBI installation directory\webapps\webroot\WEB-INF\classes\com\fr\function, as shown in the following figure.
The file can be placed in any location in the FineBI project directory, but it must correspond to the location in the package in the java file. For example, the code in this example is:
package com.fr.function;
Therefore, you need to place the CLASS file in FineBI installation directory\webapps\webroot\WEB-INF\classes\com\fr\function directory.
Similarly, you need to place the CLASS file in FineBI installation directory\webapps\webroot\WEB-INF\classes\com when the code is:
package com;
After the CLASS file for the function is generated, you need to register the custom function in the FineReport designer for use.
Build remote connection between the FineReport designer and the FineBI project. Choose Server > Function Manager, add a function named StringCat, select the defined StringCat class, and click OK, as shown in the following figure.
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
Submitted successfully
Network busy