JS Use Built-in Formulas in JavaScript

  • Last update:  2020-12-17
  • I. Overview

    Sometimes the report design involves writing JavaScript codes, but the codes to process some calculations or conversions are particularly complicated, such as date formatting, string interception and replacement. FineReport has built-in functions for processing dates and strings, and they can be called directly in JavaScript.

    II. Solution

    2.1 Solution 1

    Just use "${=formula}" in JS.

    For example, we need to display the current date after clicking the button, so write the following JavaScript code in the button's Click event:

    var rq='${=today()}'; 
    alert(rq);

    1606374625872638.png


    2.2 Solution 2

    Use the function FR.remoteEvaluate('=formula') to execute formulas.

    For example, write the following JavaScript code in the button Click event:

    var rq=FR.remoteEvaluate('=format(today(),"yyyy-MM-dd")');
    alert(rq);

    1606374625612912.png

    This can also display the current date.

    Using these two methods, you can easily mix JavaScript code with the formulas in FineReport, which greatly improves the efficiency of codes.


    2.3 Use parameters

    If passing parameters to formula, string concatenation is required.

    In the following example, parameter name is "sale" while the parameter value is "Sun"

    var area=FR.remoteEvaluate('=sql("FRDemoEN","SELECT Region from Sales_Volume where Salesperson=\''+sale+'\'",1,1)');
    alert(area);

    1606374625691701.png


    Note 1: In order to make function sql() take effect, you need to login the decision-making platform and turn off the Script call formula restriction in Security tab.

    1606374625253528.png

    Note 2: The mobile terminal App DataAnalyst V9.0 and later versions no longer support the function FR.remoteEvaluate(formula).

    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