We will create a vehicle group table. We don't have much choice about the name in this as it has to start with our prefix, and end with Group; therefore, it will be ConVMSVehicleGroup. To create the table, follow these steps:
- Using the recipe for creating EDTs, create a vehicle group EDT using the following parameters:
Property |
Value |
Name |
ConVMSVehicleGroupId |
Label |
Vehicle group |
Help Text |
Used to group vehicles for sorting, filtering, and reporting |
Extends |
SysGroup |
- Save the EDT, but don't close the designer.
- From within the project, choose to create a new item.
- Choose Data Model from the left-hand list, and select Table from the right.
- Enter ConVMSVehicleGroup in the Name field and click Add.
- This opens the table designer in a new tab. From the project, drag the ConVMSVehicleGroupId EDT on top of the Fields node in the table, as shown in the following screenshot:
- This creates the field with the same name as the EDT. As this is our table, we should remove the prefix and name it VehicleGroupId.
- Click Save.
- We can now complete our EDT, open the ConVMSVehicleGroupId EDT (or select the tab if it is still open), and enter ConVMSVehicleGroup in the Reference Table property.
- Right-click on the Table References node, and select New | Table Reference.
- In the property sheet, select the Related Field property, and then select VehicleGroupId from the drop-down list.
If the drop-down list is blank, it means that the table is not saved or the Reference Table was typed incorrectly.
- Check that the result is shown as follows:
- Save the EDT, and close its designer. This should make the active tab the ConVMSVehicleGroup table designer; if not, reselect it.
- From Application Explorer, which is opened from the View menu, expand Data Types, and then expand Extended Data Types.
- Locate the Name field, and drag it onto the Fields node of our table. You can also just type the Name field directly into the property value.
- We will now need to add an index; even though this table will only have a few records, we need to ensure that the ID field is unique. Right-click on the Indexes node, and choose New Index.
- With the new index highlighted, press the F2 function key and rename it to GroupIdx. Change the Alternate Key property to Yes. All unique indexes that will be the primary key must have this set to Yes.
- Drag the VehicleGroupId field on top of this index, adding it to the index.
The default for indexes is to create a unique index, so they are correct in this case. Indexes will be discussed later in this chapter.
- Open the VehicleGroupId field properties, and set the Mandatory property to Yes, AllowEdit to No, and leave AllowEditOnCreate as Yes.
Since we will leave AllowEditOnCreate as Yes, we can enter the ID, but not change it after the record is saved; this helps enforce referential integrity. The Mandatory, AllowEdit, and AllowEditOnCreate field properties only affect data manipulated through a form. These restrictions aren't enforced when updating data through code.
- We can now complete the table properties select the table node in the table design (the table name), and complete the property sheet as follows:
Property |
Value |
Comment |
Label |
Vehicle groups |
This is the plural name that appears to the user. VehicleGroupTable is a good label ID for this, as it gives context to others that might want to reuse this label. |
Title Field 1 |
VehicleGroupId |
These two fields appear in automatic titles generated when this table is used as a title data source. |
Title Field 2 |
Name |
|
Cache Lookup |
Found |
This is linked to the table type, and warnings will be generated should an inappropriate cache level be selected.
None: no caching is fetched from the DB every time.
NotInTTS: Fetched once per transaction.
Found: Cached once found, not looked up again.
EntireTable: The entire table is loaded into memory.
The cache is only invalidated when records are updated or flushed. |
Clustered Index |
GroupIdx |
This index is created as a clustered index.
Clustered indexes are useful as they include the entire record in the index, avoiding a bookmark lookup. This makes them efficient, but the key should always increment, such as a sales order ID; otherwise, it will need to reorganize the index when records are inserted. This table is small, so it won't cause a performance issue. It will also sort the table in Vehicle Group order. |
Primary Index |
GroupIdx |
This defines the primary index and is used when creating foreign key joins for this table. |
Table Group |
Group |
This should always be Group for a group table. Please refer to the table of table groups in the Introduction section. |
Created By
Created Date Time
Modified By
Modified Date Time
|
Yes |
This creates and maintains the Created by tracking fields and is useful if we want to know who created and changed the record, and when. |
Developer Documentation
|
The ConVMSVehicleGroup table contains definitions of
vehicle groups. |
This is required for best practice and should contain information that other developers should understand about the table. |
FormRef
|
ConVMSVehicleGroup |
This is a reference to the display menu item that references the form that is used to view the data in this table. When you choose View details in the user interface, it is this property that is used to determine which form should be opened. It is fine to fill this in now for speed, but the build will fail unless we have created the form and menu items. |
- All visible fields should be placed in a field group. Since this is a group table with two fields, we only need an Overview field group. Right-click on the Field groups node, and choose New Group.
- Press F2 to rename the group to Overview and enter Overview in the label property before clicking the ellipsis button in the value. This opens the Label Lookup form.
- Select Match exactly, and click search (the magnifying glass icon). Scroll down to find the first @SYS label with no description or one that exactly matches our intent, as shown in the following screenshot:
- Select the @SYS9039 label and click Paste label.
There are some labels provided by the system for purposes like this, and it is useful to remember them. Two common ones are @SYS9039 for Overview field groups and @SYS318405 for Details field groups (with the Description [group]Details).
- Drag the two fields onto the group, and order them so that VehicleId is first in the list.
- In order for any automatic lookups to this table to show both the ID and Description fields, add both fields to the AutoLookup field group.
- We can skip to the Methods node, where best practice dictates we need to provide the Find and Exist methods.
- Right-click on the Methods node, and choose New Method.
- This will open the code editor, which now contains all methods, and will create a simple method stub, as shown in the following block:
/// <summary>
///
/// </summary>
private void Method1()
{
}
- Remove the XML documentation comment section and the method declaration, and then create the Find method as follows:
public static ConVMSVehicleGroup Find(ConVMSVehicleGroupId _groupId, boolean _forUpdate = false)
{
ConVMSVehicleGroup vehGroup;
if (_groupId != '')
{
vehGroup.selectForUpdate(_forUpdate);
select firstonly * from vehGroup
where vehGroup.VehicleGroupId == _groupId;
}
return vehGroup;
}
- Create a blank line above the method declaration and type three slashes (///), which causes SCM to create the XML documentation based on the method declaration. Fill in this documentation as follows:
/// <summary>
/// Returns a record in <c>ConVMSVehicleGroup</c>based on the _groupId
/// parameter
/// </summary>
/// <param name = "_groupId">The Vehicle group ID to find</param>
/// <param name = "_forUpdate">True if the record should be selected for
/// update</param>
/// <returns>The <c>ConVMSVehicleGroup</c> record</returns>
Should the supplied vehicle group not be found, it will return an empty buffer (where the system RecId field is zero). The _forUpdate parameter is explained in the There's more... section.
- Now, to create the Exist method, go to the end of our Find method and create a new line after the method's end brace and just before the final brace for the table, and type as follows:
/// <summary>
/// Checks if a record exists in <c>ConVMSVehicleGroup</c>
/// </summary>
/// <param name = "_groupId">
/// The Vehicle group ID to find
/// </param>
/// <returns>
/// True if found
/// </returns>
public static boolean Exist(ConVMSVehicleGroupId _groupId)
{
ConVMSVehicleGroup vehGroup;
if (_groupId != '')
{
select firstonly RecId
from vehGroup
where vehGroup.VehicleGroupId == _groupId;
}
return (vehGroup.RecId != 0);
}
- We will have two tabs open, the code editor and the table designer. Close the code editor and save the changes. Then close and save the table designer.