Custom function to achieve table verification

  • Last update:January 20, 2021
  • 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  
    para1report name
    para2

    A list of parameter values passed to the report

    The format is as follows: "[{name:para1name,value:para1value},{name:para2name,value:para2value},......]"

    para3Get the cell column number, starting from 0
    para4Get the cell column number, starting from 0

    Example:

    ExampleExplanation
    ReportCheck("reportcheck1.cpt","[{name:max,value:100},{name:min,value:0}]",1,0)Get the B1 cell value calculated by the incoming parameter of reportcheck1
    ReportCheck('reportcheck1.cpt','[ {name:max,value:"+$a+"} , {name:min,value:"+$b+"} ]',1,0)

    Support value dynamic change

    ReportCheck("reportcheck1.cpt","[]",0,0)If there is no parameter, the second parameter value is set to "[]" to get the value of A1 cell of reportcheck1


    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:

    https://github.com/finereport-overseas/example/blob/release/10.0/src/main/java/com/fr/function/ReportCheck.java


    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:

    企业微信截图_1608084973325.png

    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:

    企业微信截图_16080870957086.png

    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:

    企业微信截图_1608087237678.png

    Add verification information as shown in the following table:

    Validation FormulaAlert InformationFormula 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.


    III. Template download

    Attachment List


    Theme: Secondary Development
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy