How to do it...

We will create a Vehicle group table. We don't have much choice on the name in this as it has to start with our prefix, and end with Group; therefore, it will be ConWHSVehicleGroup. To create this table, follow these steps:

  1. Using the recipe for creating EDTs, create a Vehicle group EDT using the following parameters:

Property

Value

Name

ConWHSVehicleGroupId

Label

Vehicle group

Help Text

The vehicle group id

Extends

SysGroup

  1. Save the EDT, but don't close the designer.
  2. From within the project, choose to create a new item.
  3. Choose Data Model from the left-hand list and select Table from the right.
  4. Enter ConWHSVehicleGroup in the Name field and press Add.
  5. This opens the table designer in a new tab. From the project, drag the ConWHSVehicleGroupId EDT on top of the Fields node in our table, as shown in the following screenshot:
  1. 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.
  2. We can now complete our EDT, open the ConWHSVehicleGroupId EDT (or select the tab if it is still open), and enter ConWHSVehicleGroup in the Reference Table property.
  3. Right-click on the Table References node and select New | Table Reference.
  4. In the property sheet, select the Related Field property and then select VehicleGroupId from the drop-down list.
If the dropdown is blank, it is likely that the Reference Table property on the table was mistyped.
  1. Save the EDT and close its designer. This should make the active tab the ConWHSVehicleGroup table designer; if not, reselect it.
  2. From Application Explorer, which is opened from the View menu, expand Data Types and then expand Extended Data Types.
  3. Locate the Description field, and drag it onto the Fields node of our table.
This can be done by selecting the first EDT in the list and typing description until you can see it in view.
  1. We will now need to add an index; even though this table will only have a few records, we will need to ensure that the ID field is unique. Right-click on the Indexes node and choose New Index.
  2. With the new index highlighted, press F2 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.
At the time of writing, this property still needs to be set to yes in order to support certain data import and export scenarios and may be removed. You will get a best practice deviation warning should the primary key not have this property set.
  1. Drag the VehicleGroupId field on top of the new index.
The defaults for indexes to create a unique index, so they are correct in this case. Indexes will be discussed later in this chapter.
  1. Open the field's 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, Allow Edit, and Allow Edit On Create field properties only affect data manipulated through a form. These restrictions aren't enforced when updating data through code.
  1. 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.

Title Field 1

VehicleGroupId

This appears in the title of forms.

Title Field 2

Description

Cache lookup

Found

None: no caching is fetched from the DB every time.

NotInTTS: Fetched once per transaction

Found: Cached once found, not looked up again

EntireTable: 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 to this table.

Table Group

Group

Setup tables should always be Group tables.

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 ConWHSVehicleGroup table contains definitions of vehicle groups.

This is required for best practice and should contain anything that other developers should understand about the table.

Form Ref

ConWHSVehicleGroup

This should be left blank until we have created the form, and resulting menu item. This allows the user interface to know which form to open when viewing details via a foreign key.

The pattern states that this should be the same name as the table.

Remember that Label, Help Text, and Developer Documentation require a label in each of your supported languages.
  1. We will now need to create a field group; as we will use a Simple list design pattern for this type of table, we will only need one. Right-click on the Field groups node and select New Group.
Field groups are used mainly in the user interface. We can add the group to the user interface and the controls will match the fields in the field group. All visible fields must be in a field group.
  1. Select New group and rename the group to Overview by pressing F2.
  2. Create a label for Overview.
As we use some labels in many contexts, type in Overview for the label ID. The label ID that we use for the field group's Label property will be @ConWHS:Overview. For common labels, this makes them easier to remember and read without having to open the label editor.
  1. In the property sheet, enter Overview as the Label property and click on the lookup button to locate the label we created in the previous step.
We can reuse existing labels, and this is fine if we are sure that the context is correct. If we chose a label called Overview, we will run the risk that Microsoft may rename to Financial overview, for example.
Also, only reuse @SYS labels--you may find that you have used a label in a sample application that isn't shipped to the production environment.
  1. Drag the two fields onto the group and order them so that VehicleId is first in the list.
  1. In order for any automatic lookups to this table to show both ID and Description fields, add both fields to the AutoLookup field group.
  1. We can skip to the Methods node, where best practice dictates we need to provide the Find and Exist methods.
Methods in Operations have changed the naming convention, in that they should now start with a capital letter. You will find many standard methods still start with a lowercase letter, as they have not been refactored.
  1. Right-click on the Methods node and chose New Method.
This opens the code editor. Elements that contain code, such as tables and forms, can be opened in both designer and code editors.
  1. The code editor has changed in this release so that all methods are shown in the same editor. We are given a method stub, as shown here:
/// <summary> 
///
/// </summary>
private void Method1()
{
}
We can see that the first line in the editor is public class ConWHSVehicleGroup extends Common. All methods are created inside the two out braces.
  1. Remove the XML documentation comment section and create the Find method as follows:
public static ConWHSVehicleGroup Find( 
ConWHSVehicleGroupId _groupId,
boolean _forUpdate = false)
{
ConWHSVehicleGroup vehGroup;

vehGroup.selectForUpdate(_forUpdate);

select firstonly * from vehGroup
where vehGroup.VehicleGroupId == _groupId;

return vehGroup;
}
  1. Create a blank line above the method declaration and type three slashes (///), which causes Operations to create the XML documentation based on the method declaration. Fill in this documentation as follows:
/// <summary> 
/// Returns a record in <c>ConWHSVehicleGroup</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>ConWHSVehicleGroup</c> record
///</returns>
Should the supplied vehicle group not be found, it returns an empty buffer (where the system RecId field is zero). The _forUpdate parameter is explained in the There's more... section.
  1. 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>ConWHSVehicleGroup</c>
/// </summary>
/// <param name = "_groupId">
/// The Vehicle group ID to find
/// </param>
/// <returns>
/// True if found
/// </returns>
public static boolean Exist(
ConWHSVehicleGroupId _groupId)
{
ConWHSVehicleGroup vehGroup;
if (_groupId != '')
{
select firstonly RecId from vehGroup
where vehGroup.VehicleGroupId == _groupId;
}

return (vehGroup.RecId != 0);
}
These methods are very similar, and it is better to write the Find method and copy it in order to create the Exist method.
  1. We will have two tabs open, the code editor and the table designer. Since the code editor will be open, close this first, saving the changes. Then close and save the table designer.
  1. Finally, we will need to synchronize the database so that the table is created within the SQL Server. Before we do this, we will need to build the model by following these steps:
    1. From the menu, select Operations and then Build models....
    2. Check ConWHSVehicleManagement from the list and press Build.
  1. To synchronize the database with the table definitions, right-click on the project in the Solution Explorer and choose Synchronize ConWHSVehicleManagement with Database.
  2. This will start the process and will be visible in the Output window. We will only need to do this when we need to either run unit tests or tests within our environment.
..................Content has been hidden....................

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