I. Overview
1.1 Requirement
When performing data entry in a report, we often wish to know whether or not data entry succeeds. How can we get the returned value of data entry success/failure through JS?
1.2 Solution
There are three event types for widgets:
1) JavaScript
2) Commit to Database
3) Send Email
When Commit to Database is selected as the event type, set Callback Function to return some information. The return parameter is fr_submitinfo and whether the value of fr_submitinfo.success is true or false can tell whether data entry is successful: if true, data entry succeeds, or it fails.
Note
The fr_submitinfo interface parameter applies to two scenarios: one is the above-mentioned “Callback events”, the other is “After Data Entry events”, which indicates that in an After Data Entry event, fr_submitinfo can be used to judge whether the background program is normally executed.
II. Sample
2.1 Steps
1) Create a blank template, add several text widgets to the template and then add a button widget to G2. The report body is set as follows:
2) Add a Click event to the button widget, whose event type is Commit to Database, and then bind a database to the button, as shown in the figure below:
3) Click the Set Callback Function button at the bottom of the dialog box to determine the next step according to whether data entry succeeds. If data entry succeeds, then a message “Submitted successfully” will appear; if it fails, then a message “Submission Failed” will appear
Input the following JS codes:
if (fr_submitinfo.success) {
FR.Msg.toast('Submitted successfully');
} else {
FR.Msg.toast('Submission Failed');
}
Note
Success only indicates normal background program execution, rather than successful data submission.
4) Click Data Entry Preview, fill in the data on the Web and click the submit button. If the data is submitted successfully, a message “Submitted successfully” will appear; or a message “Submission Failed” will appear.
2.2 Preview
Save the template and click [Pagination Preview]. The effect on a PC is shown in the figure below: