I. Overview
1. Expected effect
When submit the data entry report, the value of editing cell needs to be compared with the value of a parameter or cell in another report, which can be achieved through custom function.
For example, check the score entered in cell D2 in the template reportcheck2.cpt, and compare the value in reportcheck1.cpt.
The value entered by D2 cannot be greater than the maximum value or less than the minimum value in reportcheck1.cpt.
2. Implementation ideas
In the custom function implemented by Java, read the report, pass in the parameter value and execute. Take the value of a cell from the report result after execution and return it. The returned value can be used for data verification in the data entry form.
3. Function introduction
This method is implemented by the custom function reportcheck.
Reportcheck function: reportcheck (para1, para2, para3, para4) to get the value of a cell in the report
Note: it only supports Tomcat server.
Parameter | Explanation |
---|---|
para1 | report name |
para2 | A list of parameter values passed to the report The format is as follows: "[{name:para1name,value:para1value},{name:para2name,value:para2value},......]" |
para3 | Get the cell column number, starting from 0 |
para4 | Get the cell column number, starting from 0 |
Example:
II. Examples
Note 1: the custom function reportcheck only supports the use of Tomcat server.
Note 2: this example is only for principle introduction, so the comparison object directly refers to the parameter value. In fact, it may be that the report obtains data according to the parameters passed in, and the values of some cells after the report is executed are the same as in this example.
1. Writing custom functions
to write ReportCheck.java The function code is as follows:
2. Compiling custom functions
1) generate class file
compile ReportCheck.java , generate class ReportCheck.class , ReportCheck$ TpObj.class .
Note: when compiling, you need to import the finereport project jar package, including all the package under the %FR_HOME%/lib, %FR_HOME%/server/lib and %FR_HOME%/webapps/webroot/WEB-INF/lib,also import tools.jar of JDK. For details, see launching designer in idea.
2) import class file
This class is defined in the package com.fr.function, copy the generated class file to
%FR_HOME%\webapps\webroot\WEB-INF\classes\com\fr\function, as shown in the figure below:
3. Registering custom functions
Open the designer, select server > function manager, add a custom function ReportCheck, and select class com.fr.function.reportcheck, as shown in the figure below:
In this way, the custom function ReportCheck is registered, and users can use the custom function in all templates in the project.
4. Template setting
1) new template ReportCheck1
New normal report %fr_ HOME%\webapps\webroot\WEB-INF\reportlets\reportcheck1.cpt
The report style is as follows:
2) new template reportcheck2
New normal report %fr_ HOME%\webapps\webroot\WEB-INF\reportlets\reportcheck2.cpt
The report style is as follows:
5. Using custom functions
Open the reportcheck2.cpt template, click template > data entry attributes > data validation to set the validation formula, as shown in the figure below:
Add verification information as shown in the following table:
Validation Formula | Alert Information | Formula description |
---|---|---|
D2 <= ReportCheck("reportcheck1.cpt","[{name:max,value:90},{name:min,value:0}]",1,0) | "The score is beyond the maximum" | Pass in two parameters to reportcheck1, max value is 90, min value is 0, and take the values of B1 and B2 cells in the first and second row of the second column after execution, which is the value of B1 and B2. |
D2 >= ReportCheck("reportcheck1.cpt","[{name:max,value:90},{name:min,value:0}]",1,1) | "The score is below the minimum" |
6. Effect preview
Save the template, restart the Tomcat server, and enter: http://localhost :8080/webroot/decision/view/report?viewlet=reportcheck2.cpt&op=write
Score input 120, click data verification, prompt: The score is beyond the maximum, as shown in the figure below:
Score input - 10, prompt: The score is below the minimum. As shown in the figure below:
Score input 80, validate successfully. As shown in the figure below:
Note 1: mobile terminal is not supported.
Note 2: only Tomcat server is supported.
Note 3: only preview is supported.