We will first create the worksheet header table, which will be a vehicle service order table:
- Create a new table named ConWHSVehicleServiceTable.
- Create a primary key EDT, ConWHSVehicleServiceId; this time, extend Num. Complete the Label and Help Text properties with appropriate labels.
- Drag the EDT from Solution Explorer to the Fields node of our table, and rename it to ServiceId.
- Complete the ServiceId field as an ID field: Mandatory = Yes, Allow Edit = No, Allow Edit On Create = Yes.
- Complete the relation information on the EDT.
- Create the primary key index as ServiceIdx with ServiceId as the only field.
- Set the Clustered Index and Primary Index properties as ServiceIdx.
- Drag the ConWHSVehicleId EDT to our table and rename it to VehicleId.
- Make the VehicleId field mandatory. The decision to make the field editable depends on the associated logic (referential integrity) and the business requirement.
- Create a foreign key relation for ConWHSVehicleId to ConWHSVehicleTable.VehicleId.
The cardinality should be OneMore as it is mandatory. On Delete should be Restricted on foreign key relations to main tables.
- Drag the Description EDT onto our table from the Application Explorer.
- Create a new Base Enum for the service status, as defined here:
Property | Value |
Name | ConWHSVehicleServiceStatus |
Label | Status (for example @SYS36398) |
Help | The service order status |
Is Extensible | True Remember that we can't use > or < comparisons in code with this set. |
Elements | Label |
None | <empty> |
Confirmed | Confirmed |
Complete | Complete |
Cancelled | Cancelled |
- Drag ConWHSVehicleServiceStatus to our table as ServiceStatus.
- Save and drag the new Enum to our table and rename it to ServiceStatus.
- Make the ServiceStatus field read only. Allow Edit and Allow Edit On Create should be No. Status fields should be controlled through business logic.
- Create date EDTs ConWHSVehicleServiceDateReq 'Requested service date' and ConWHSVehicleServiceDateConf 'Confirmed service date'. The dates should extend TransDate. Label appropriately and drag to the new table.
- Rename the fields to ServiceDateRequested and ServiceDateConfirmed.
- Complete the table properties as shown here:
Property |
Value |
Label |
Vehicle service orders |
Title Field 1 |
ServiceId |
Title Field 2 |
Description |
Cache lookup |
Found |
Clustered Index |
ServiceIdx |
Primary Index |
ServiceIdx |
Table Group |
WorksheetHeader |
Created By Created Date Time Modified By Modified Date Time |
Yes |
Developer Documentation |
ConWHSVehicleServiceTable contains vehicle service order records. |
Form Ref |
Blank until we have created the form |
- Create the field groups as follows:
Group / fields |
Label |
Overview
|
Overview |
Details
|
Details |
ServiceDates
|
Service dates |
- Create the now usual Find and Exist methods using ServiceId as the key.
- You can also create your own validation on the service dates.
- Finally, we will introduce the validateWrite method. This is to enforce the requirement that only service orders at status confirmed or less can be changed; the method should be written as follows:
public boolean validateWrite()
{
boolean ret;
ret = super();
ret = ret && this.CheckCanEdit();
return ret;
}
public boolean CheckCanEdit()
{
If (!this.CanEdit())
{
//Service order cannot be changed.
return checkFailed("@ConWHS:ConWHS33");
}
return true;
}
public boolean CanEdit()
{
switch (this.ServiceStatus)
{
case ConWHSVehicleServiceStatus::None:
case ConWHSVehicleServiceStatus::Confirmed:
return true;
}
return false;
}
- Finally, we will write a method that initializes the defaults from the main table record, that is, vehicle, when it is selected. Write the following method:
public void InitFromVehicleTable(ConWHSVehicleTable _vehicle)
{
this.Description = _vehicle.Description;
}
- Then, override modifiedField as follows:
public void modifiedField(FieldId _fieldId)
{
super(_fieldId);
switch(_fieldId)
{
case fieldNum(ConWHSVehicleServiceTable,
VehicleId):
this.InitFromVehicleTable(
ConWHSVehicleTable::Find(
this.VehicleId));
break;
}
}
- Save the table and close the editor tabs.