How to do it...

To create the parameter table follow these steps:

  1. Create a new table called ConWHSVehiclePararameters; again, the prefix and suffix is based on practice. Usually, the name will only be <Prefix>+<Module>+Parameters.
  2. 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

  1. Drag the ConWHSVehicleGroupId EDT onto the Fields node and rename it to DefaultVehicleGroupId.
  2. Drag the ParametersKey EDT from the Application Explorer to our Fields node.
  3. Rename it to Key and change the Visible property to No.
This is only used as a constraint to limit the table to only having one record. All visible fields need to be in a field group.
  1. Create a field group called Defaults and set the Label property. Use the lookup to locate a suitable label.
The label @SYS334126 has a description indicating that we can use this for a defaults field group. You will see other examples that are clearly unsuitable by reading the Description field.
  1. Drag the DefaultVehicleGroupId field to the new Defaults field group.
We will use this on the parameter form so that it has the heading as Defaults. This is why we don't need to change the field's label to specify context.
  1. Right-click on the Relations node and select New | Foreign Key Relation.
  2. 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.

  1. Right-click on Relation and choose New | Normal.
  2. In the Field property, specify the foreign key (the field in this table), DefaultVehicleGroupId.
  3. In the Related Field property, specify the key in the parent table: VehicleGroupId.
  4. 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.
  5. 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;
}
  1. 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;
}
  1. 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");
}
This method is called whenever we try and delete a record, either through the UI or in code. The call to super() that we removed, calls doDelete(), which in turn tells the kernel to delete the record.
  1. 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;
}
We want to tell Operations to write the record, and then flush the cache. This is why super() is the first line.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.126.248