In the training material I am going over it is setting 3 DialogFields as such(I also am showing the table declaration:
CustTable custTable;
dlgCust = dlg.addField(extendedTypeStr(CustVendAc),"Customer account");
dlgGrp = dlg.addField(extendedTypeStr(CustGroupId));
dlgCur = dlg.addField(extendedTypeStr(CurrencyCode));
Then it tries to save the values from the dialog box into the custTable
custTable.AccountNum = dlgCust.value();
custTable.CustGroup = dlgGrp.value();
custTable.Currency = dlgCur.value();
Why is it setting the DialogFields to one extended type just to move it to another? CustVendAc, CustGroupId, and CurrencyCode all do not exist in CustTable. What is the point of doing this?
A side question that is:
The lab I'm working on for this asks me:
Create a new class that will prompt the user for a new customer account number, the name and all fields that are mandatory for the customer records. Use existing methods to validate the record before inserting the record into the database. In the case that not all data was entered, throw an error exception that has the error message: "Please enter all required fields." The code to create the record must be inside a try/catch statement. This must include a catch for the error exception type and display the message: "An error occurred. Please try again.".
It says to get the account number, the name, and all the fields that are mandatory for the customer record. How am I suppose to determine this on my own? I looked at the table and at the new Customer form and it asks for more information than what their solution gives... how do you determine what fields to ask for then?
CustTable.AccountNum
field in CustTable
is of CustAccount
type, which extends CustVendAc
EDT. So basically, they both are of the same type.
CustTable.CustGroup
is of CustGroupId
type, so it is ok.
CustTable.Currency
is of CustCurrencyCode
type, which extends CurrencyCode
.
Use existing methods to validate the record before inserting the record into the database.
Use custTable.validateWrite
method to validate if the record can be created. It will return false
if some mandatory records are missing and will show infolog with error message as well.
It says to get the account number, the name, and all the fields that are mandatory for the customer record. How am I suppose to determine this on my own?
Each field in a table has Mandatory
property.
The code woulld look like this:
try
{
custTable.initValue();
custTable.AccountNum = dlgCust.value();
custTable.CustGroup = dlgGrp.value();
custTable.Currency = dlgCur.value();
//Other mendatory fields like customer name
if (custTable.validateWrite())
{
ttsBegin;
custTable.insert();
ttsCommit;
}
else
{
throw error("Please enter all required fields");
}
}
catch
{
error("An error occurred. Please try again");
}