How to do it...

We will first create the worksheet header table, which will be a vehicle service order table:

  1. Create a new table named ConWHSVehicleServiceTable.
  2. Create a primary key EDT, ConWHSVehicleServiceId; this time, extend Num. Complete the Label and Help Text properties with appropriate labels.
  3. Drag the EDT from Solution Explorer to the Fields node of our table, and rename it to ServiceId.
  4. Complete the ServiceId field as an ID field: Mandatory = Yes, Allow Edit = No, Allow Edit On Create = Yes.
  5. Complete the relation information on the EDT.
  6. Create the primary key index as ServiceIdx with ServiceId as the only field.
  7. Set the Clustered Index and Primary Index properties as ServiceIdx.
  8. Drag the ConWHSVehicleId EDT to our table and rename it to VehicleId.
  9. Make the VehicleId field mandatory. The decision to make the field editable depends on the associated logic (referential integrity) and the business requirement.
  10. 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.
  1. Drag the Description EDT onto our table from the Application Explorer.
  2. 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
  1. Drag ConWHSVehicleServiceStatus to our table as ServiceStatus.
  2. Save and drag the new Enum to our table and rename it to ServiceStatus.
  3. Make the ServiceStatus field read only. Allow Edit and Allow Edit On Create should be No. Status fields should be controlled through business logic.
  4. 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.
  5. Rename the fields to ServiceDateRequested and ServiceDateConfirmed.
  6. 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

  1. Create the field groups as follows:

Group / fields

Label

Overview

  • ServiceId
  • VehicleId
  • Description
  • ServiceStatus

Overview

Details

  • ServiceId
  • VehicleId
  • Description
  • ServiceStatus

Details

ServiceDates

  • ServiceDateRequested
  • ServiceDateConfirmed

Service dates

  1. Create the now usual Find and Exist methods using ServiceId as the key.
  2. You can also create your own validation on the service dates.
  3. 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;
}
  1. 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;
}
  1. 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;
}
}
  1. Save the table and close the editor tabs.
..................Content has been hidden....................

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