I. Overview
1. Problem description
When making a data entry template, it is often encountered that multiple indicators are checked in the cell widget, and the following two situations occur:
1) When there is a primary key, the modification operation is performed, but only one value is retained after the submission is successful.
For example:
We checked the 4 indicators of "Jiajiale, Kangfu food, Miaosheng, and Weiquan" in the "drop-down checkbox" widget and submitted them to the database. After refreshing the page, we found that only the last selected indicator was retained.
2) When the primary key does not exist, the add operation is performed. After the submission is successful, the database will store multiple data.
For example:
Use the "Product" table to add a piece of test data. After the supplier selects 3 indicators and submits it for storage, it is found that 3 new pieces of data have been added to the "Product" table.
And we hope that after submitting multiple selection values in the "drop-down checkbox", multiple values can be displayed correctly in a piece of data. How to deal with it?
2. Solution
The return value type of the "drop-down checkbox" defaults to "Array". In the above two cases, the return value type needs to be "String", which leads to incorrect filling results.
Method: Change the return value type of "drop-down checkbox" from "Array" to "String".
Note: The solution for the modification operation and the addition operation is the same.
II. Example
1. Prepare template
Open the built-in template: %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\Form\RowForm\Simple_Row-based_Form.cpt
2. Set drop-down checkbox widget
Modify the D3 widget to "drop-down checkbox" widget, the return value type is "String", other defaults. The steps are shown in the figure below:
3. Set data dictionary
Set the "Data Dictionary" to cell D3, set the type to "Database Table", select "FRDemo" for the database, select "Supplier" for the database table, the actual value is "SupplierID", and the display value is "Company_name". The steps are shown in the figure below:
4. Set formula form
Select cell D3, set "Cell Attributes>Display>Formula Form", define the formula form: sql("FRDemo", "select DISTINCT Company_name from Supplier where SupplierID in (" + $$$ + ")", 1)
The steps are shown in the figure below:
Note: The formula sql("FRDemo", "select DISTINCT Company_name from Supplier where SupplierID in (" + $$$ + ")", 1) makes the cell content displayed when the mouse leaves the cell display value instead of actual value.
5. Modify field type
The type of the "SupplierID" field in the designer's built-in database table "Product" is integer, and it needs to be modified to the text type before the string type value can be stored. Otherwise, an error will be prompted when submitting to the database: the data column type does not match.
6. Preview effect
Save the template, click "Data Entry Preview", the effect is shown in the following figure:
Note: Both App and H5 are supported.
Note: The drop-down checkbox widget, radio button group widget, checkbox group widget and other multi-select widgets have similar problems, please refer to this document for handling.
III. Download template
Please refer to the completed template: %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\DataEntry\DataEntryApplication\Data_entry_mutiple-value.cpt
Click to download: