To create the parameter table follow these steps:
- Create a new table called ConWHSVehiclePararameters; again, the prefix and suffix is based on practice. Usually, the name will only be <Prefix>+<Module>+Parameters.
- Set the table's parameters as follows:
Property |
Value |
Label |
Vehicle management parameters |
Cache lookup |
Found |
Table Group |
Parameter |
Created By Created Date Time Modified By Modified Date Time |
Yes |
Developer Documentation |
The ConWHSVehicleParameters table stores the parameters for the Vehicle management solution |
- Drag the ConWHSVehicleGroupId EDT onto the Fields node and rename it to DefaultVehicleGroupId.
- Drag the ParametersKey EDT from the Application Explorer to our Fields node.
- Rename it to Key and change the Visible property to No.
- Create a field group called Defaults and set the Label property. Use the lookup to locate a suitable label.
- Drag the DefaultVehicleGroupId field to the new Defaults field group.
- Right-click on the Relations node and select New | Foreign Key Relation.
- Complete the parameters as follows; if not specified, leave as default:
Parameter |
Value |
Comment |
Name |
ConWHSVehicleGroup |
The name of the relation is usually the name of the table, unless we have two foreign keys to the same table. |
Related Table |
ConWHSVehicleGroup |
The table to which our foreign key relates. |
Cardinality |
ZeroOne |
There will be either one or no parameter record relating to the vehicle group record. A one-to-many relationship would use ZeroMore or OneMore. |
Related Table Cardinality |
ZeroOne |
The value is not mandatory, so we can therefore relate to zero vehicle group records, or one. |
Relationship Type |
Association |
The parameter record is associated with a vehicle record. Composition would be used in header/lines datasets, where deleting the header should delete the lines records. |
On Delete |
Restricted |
This will prevent a vehicle group record from being deleted, if it is specified on this table. See the There's more section for more information on delete actions. |
Role |
This is the role of the relation, and it must be unique within this table. If UseUniqueRoleNames is Yes, we will only need to specify this if we have two foreign key relations to the same table. |
- Right-click on Relation and choose New | Normal.
- In the Field property, specify the foreign key (the field in this table), DefaultVehicleGroupId.
- In the Related Field property, specify the key in the parent table: VehicleGroupId.
- Create a new index called KeyIdx and add the Key field to it. It is unique by default, so it acts as a constraint index.
- We can now create the Find and Exist method. There is a difference for parameter tables, in that the Find method creates a record in a particular way. Create the Find method as shown in the following piece of code:
public static ConWHSVehicleParameters Find(
boolean _forupdate = false)
{
ConWHSVehicleParameters parameter;
parameter.selectForUpdate(_forupdate);
select firstonly parameter
index Key
where parameter.Key == 0;
if (!parameter && !parameter.isTmp())
{
// Create the parameter
Company::createParameter(parameter);
}
return parameter;
}
- We will use a slightly different select statement where we can write the select statement inline, which means that we don't have to declare the type as a variable; write the Exist method as follows:
public static boolean Exist()
{
return (select firstonly RecId
from ConWHSVehicleParameters).RecId != 0;
}
- We want to ensure that the record cannot be deleted. So, we will override the Delete method. Press Return at the start of the Find method to create a blank line at the top. Right-click on this blank line and choose Insert Override Method | Delete. Change the method so that it reads as follows:
public void delete()
{
throw error("@SYS23721");
}
- We set the Table Cache property to EntireTable. Whenever this table is updated, we will need to flush the cache so that the system uses the updated values. Override the update method as follows:
public void update()
{
super();
flush ConWHSVehicleParameters;
}