Most modules need a parameter table that can only consist of one record. The values in the table specify general options for the module. They typically consist of the number sequences needed for the module and default values that are used throughout the module.
In the following example, we will create a parameter table for the Car Rental
module. The following are the steps:
CarRentalParameters
, and set the label of the table to be Car rental parameters
.ParametersKey
. Then, we drag-and-drop it onto the Fields node of our newly created parameter table and change the name of the field in the table to Key
. We also change some of the properties of the Key
field in the parameter table as follows:No
No
No
KeyIdx
index and set the parameter Allow Duplicates
to No
.DefaultFilepath
and make it extend the extended data type Filename
.CarRentalParameter
table as follows:Base + default data
Edit
Found
Parameter
KeyIdx
KeyIdx
Yes
Yes
find
method for the table, which will look something like this:client server static CarRentalParameters find(boolean _forupdate = false), { CarRentalParameters parameter; // Try/catch added because of issues that // might occur during upgrade try { if (_forupdate) parameter.selectForUpdate(_forupdate); // Find the one and only record in // the table if any select firstonly parameter index KeyIdx where parameter.Key == 0; // If the record doesn't exist and // the table buffer used has not been // set as temporary, then create the record. if (!parameter && !parameter.isTmp()) Company::createParameter(parameter); } catch (Exception::DuplicateKeyException,parameter) { retry; } return parameter; }
The CarRentalParameter
table should now look like this in AOT:
We can now use the parameter table in the ImpExpFileDialog
class that we created in Chapter 7, Integrating Data. We will modify the dialog method and add the code between the NEW
comments, as shown in the following code:
public Object dialog() { // Create a new object of the DialogRunbase class dialog = new DialogRunbase("Import data from file", this); // +++ NEW +++ // Find the default filepath if it has been set // in the parameter table if the fileName variable // is empty (no value fetched while unpacking). if (!fileName) fileName = CarRentalParameters::find().DefaultFilepath; // --- NEW --- // Add the fields to the dialog and // set the initial value to be equal to // the value selected last time. dialogReadWrite = dialog.addFieldValue(typeid(ReadWrite), readWrite); dialogFileName = dialog.addFieldValue(typeid(FileName), fileName); dialogFileType = dialog.addFieldValue(typeid(FileType), fileType); dialogEntity = dialog.addFieldValue(typeid(FileEntity), entity); return dialog; }
As we haven't created a form for the parameter table yet, we will have to use the table browser to change the parameter in order to test the import/export classes. Remember to delete the usage data after implementing the changes done in the preceding code. If you don't, you will get the previous selected file location and filename instead of the file location from the parameter table.
Also, add the following methods to the parameter table. This method will be used to get the number sequence reference:
Public server static NumberSequenceReference numRefRentalId () { // scope definition NumberSeqScopeFactory::CreateDataAreaScope(selectableDataArea _dataArea = curext()); return NumberSeqReference::findReference(extendedtypenum (RentalId)); }
In the first section of this chapter, you learned how to set up a number sequence reference by adding a new class. Now, you have to create a number sequence and to link it to the number sequence reference.
The first thing that we need to do is initialize the number sequence by calling the LoadAll
method on the class NumberSequenceModuleSetup
. Create a job that can call the LoadAll
function.
Next, go to the Number sequence form and set up the number sequence by navigating to Organization administration | Common | Number sequences | Number sequences.
It is also common to be able to do this from the page in the last tab in the parameter form for the module where it is relevant to set up the number sequence. The following screenshot shows a Number Sequence form:
There are a few steps you have to perform in order to use the number sequence as well, and I will try to demonstrate how to use the number sequence for the RentalId
value in the RentalTable
form. The steps are as follows:
RentalTable
form to hold an object of the NumberSeqFormHandler
class:public class FormRun extends ObjectRun { NumberSeqFormHandler numberSeqFormHandler; }
numberSeqFormHandler
object:NumberSeqFormHandler numberSeqFormHandler() { if (!numberSeqFormHandler) { // Create a new object of the NumberSeqFormHandler // class by using the static method newForm numberSeqFormHandler = NumberSeqFormHandler::newForm(CarRentalParameters::numRefRentalId().NumberSequenceId,element, RentalTable_DS, fieldnum(RentalTable, RentalId)); } return numberSeqFormHandler; }
RentalTable
data source, as shown in the following code:public void create(boolean _append = false) { element.numberSeqFormHandler().formMethodDataSourceCreatePre(); super(_append); element.numberSeqFormHandler().formMethodDataSourceCreate(); } public void delete() { element.numberSeqFormHandler().formMethodDataSourceDelete(); super(); } public void write() { super(); element.numberSeqFormHandler().formMethodDataSourceWrite(); }
RentalTable
form now and creating a new record should create a new value for the RentalId
.18.216.34.146