When the user clicks Clear to remove
nondefault content from the single-record layout, the clearAllFields function
runs. The function sets up the layout so that when the user types
data and clicks Save, the new typed data updates
an existing database row.
- Click the Source tab.
- Find the clearAllFields function and make
it as follows:
function clearAllFields(event Event in)
saveID INT = selectedPayment.paymentID; // retain the key
selectedPayment = new PaymentRec{};
selectedPayment.paymentID = saveID;
selectedPayment_form.publish();
end
The code retains the record key
for use in a subsequent update of the database. The code then creates
a record, assigns it to the selectedPayment variable,
assigns the saved key value to that variable, and publishes the variable
to the single-record layout.
- Complete the function that is invoked when the user clicks Save:
- Find the function, which is named selectedPayment_form_Submit.
- Make the function as follows:
function selectedPayment_form_Submit(event Event in)
selectedPayment_category_comboBox.value
= PaymentLib.getCategoryNum(selectedPayment_category_comboBox.value);
if (selectedPayment_form.isValid())
selectedPayment_form.commit();
selectedPayment_category_comboBox.value =
PaymentLib.getCategoryDesc(selectedPayment_category_comboBox.value);
// update allPayments with new version of selectedPayment
for(i INT from 1 to allPayments.getSize())
if(allPayments[i].paymentID == selectedPayment.paymentID)
allPayments[i] = selectedPayment;
exit for;
end
end
call dbService.editPayment(selectedPayment)
returning to recordRevised
onException serviceLib.serviceExceptionHandler;
end
end
The following clause checks the validity of copying
the widget content to the related field:
if (selectedPayment_form.isValid())
A
problem arises with the Dojo combo box for Description,
because the widget content is of type STRING and the related field
is selectedPayment.category, which is of type INT.
The validation of the Dojo combo box requires that combo box include
either integers or strings, such as “1” or “20,” that can be converted
to integers.
To handle the issue, use an EGL combo widget or
ensure that the Dojo combo box includes a valid integer before validation.
The previous code demonstrates the second option, and begins by assigning
the integer:
selectedPayment_category_comboBox.value
= PaymentLib.getCategoryNum(selectedPayment_category_comboBox.value);
The function thereafter checks the validity of
the data in the single-record layout and, if the data is valid, does
as follows:
- Commits the validated data to the selectedPayment record.
This “commit” is part of MVC processing and has nothing to do with
a database commit.
- Updates the Dojo combo box in the single-record layout so that
the value of that field is again a string.
- Revises the allPayments array element that contains
the saved key value. At that point, the array element includes a copy
of the data that the user wants in the database.
- Calls the service to update a single row in the database. The
related callback function assigns the allPayments array
to the data array of the data grid, and that assignment re-renders
the grid with the updated data. The grid will be re-rendered with
data assigned in the selectedPayment_form_Submit function,
not with data retrieved from the database.
- Save the file, but do not close it. If you see
errors in your source file, compare your code to the file contents
in Finished code for PaymentFileMaintenance.egl.