JS realizes data entry linkage and generate default value

  • Last update:  2021-06-07
  • I. Overview

    1. Problem description

    We hope to realize that based on the data entry linkage, after selecting the first widget value, other linkage widgets can follow to select the first value in the selectable range. The effect is shown in the following figure:

    1.gif


    2. Realization idea

    When both the cell linkage and the widget data dictionary linkage are set, when the widget data dictionary linkage is triggered, the cell value will be cleared, causing the cell linkage to fail. So to achieve this requirement, you need to assign a value to the widget through JS. 

    Note: Mobile terminal is not supported.

    II. Example

    1. Design report

    Add drop-down box widgets to cells B1, D1, and F1, as shown in the following figure:

    2.png


    2. Add data dictionary

    Set the drop-down box data dictionary for the three widgets, select formula, enter the actual value and the display value, as shown in the following figure:

    3.png

    The three widgets differ only in actual value, the display value is $$$, and the actual values are:

    B1:sql('FRDemo','SELECT Region FROM Sales_Volume',1)

    D1:sql('FRDemo','SELECT Salesperson FROM Sales_Volume where Region="'+B1+'"',1)

    F1:sql('FRDemo','SELECT Product_types FROM Sales_Volume where Region="'+B1+'" and Salesperson="'+D1+'"',1)


    3. Set default value for widgets

    If the ‘widget needs to add a default value, you can add a default value to the widget by entering a formula, as shown in the following figure:

    4.png

    The cell formulas are:

    B1:sql('FRDemo','SELECT Region FROM Sales_Volume',1,1)

    D1:sql('FRDemo','SELECT Salesperson FROM Sales_Volume where Region="'+B1+'"',1,1)

    F1:sql('FRDemo','SELECT Product_types FROM Sales_Volume where Region="'+B1+'" and Salesperson="'+D1+'"',1,1)


    4. Add events

    Add Edit End events to B1, D1 drop-down box widgets(After Editing event can also be used) .

    1) First, click Template>Template Parameters to define a parameter row, as shown in the figure below:

    5.png

    2) Add an edit end event to the B1 widget, set the parameter row to the formula row(), as shown in the figure below:

    6.png

    The JavaScript code in B1 is as follows:

    var region = this.getValue();
    setTimeout(function() {
    var salesperson;
    var ptypes;
    var sql = 'SELECT Salesperson FROM Sales_Volume where Region="' + region + '"';
    salesperson = FR.remoteEvaluate("=sql('FRDemo','" + sql + "',1,1)");
    _g().setCellValue('D' + row, null, salesperson);
    var sql1 = 'SELECT Product_types FROM Sales_Volume where Region="' + region + '" and Salesperson="' + salesperson + '"';
    ptypes = FR.remoteEvaluate("=sql('FRDemo','" + sql1 + "',1,1)");
    _g().setCellValue('F' + row, null, ptypes);
    }, 200);

    2) Similarly, add an edit end event to the D1 widget, and set the parameter row to the formula row().

    The JavaScript code in D1 is as follows:

    var salesperson = this.getValue();
    var ptypes;
    setTimeout(function() {
    var region = _g().getCellValue('B' + row, null);
    var sql = 'SELECT Product_types FROM Sales_Volume where Region="' + region + '" and Salesperson="' + salesperson + '"';
    ptypes = FR.remoteEvaluate("=sql('FRDemo','" + sql + "',1,1)");
    _g().setCellValue('F' + row, null, ptypes);
    }, 300);

    5. Set data entry settings

    In the designer menu bar, click Template>Web Attributes, select data entry settings, and check the "Display Widgets Directly", as shown in the following figure:

    7.png


    6. Turn off script call formula restriction

    Because some formulas are called by the script in the example, you need to open the decision-making platform, click Manage> Security, and turn off "Script call formula restriction", as shown in the following figure:

    8.png


    7. Preview effect

    Save the template, click data entry preview, the effect is shown in I.1.

    III. Download template

    Click to download: Linkage_in_drop-down_box .cpt



    Attachment List


    Theme: Data Entry
    • 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