How to do it...

The first part of this is to create the data contract, which is done by following these steps:

  1. Create a new class named ConWHSVehicleGroupChangeContract.
  2. Complete the declaration as follows:
[DataContract] 
class ConWHSVehicleGroupChangeContract
extends SysOperationDataContractBase
{
ConWHSVehicleId vehicleId;
ConWHSVehicleGroupId vehicleGroupId;
}
  1. Then add the data member property methods, as shown here:
[DataMember] 
public ConWHSVehicleId vehicleID(ConWHSVehicleId
_vehicleId = vehicleID)
{
vehicleID = _vehicleID;
return vehicleID;
}
[DataMember]
public ConWHSVehicleGroupId vehicleGroupId(
ConWHSVehicleGroupId
_vehicleGroupId = vehicleGroupId)
{
vehicleGroupId = _vehicleGroupId;
return vehicleGroupId;
}

Now, to create the class that performs the update, let's follow these steps:

  1. Create a new class named ConWHSVehicleGroupChange.
  2. Within the class, declare the data contract as a global variable to the class, as follows:
public ConWHSVehicleGroupChangeContract contract; 
This allows other objects to set this property directly, which needs to be thought through carefully. It is safe in this case as we call the Run method with the contract, and call Validate within the Run method. This allows a caller to set the contract property and call Validate before Run is called.
  1. This class will have the following methods as a minimum:
    • public Run(<data contract>)
    • public boolean Validate()
    • public <class> Construct()
  2. Create these methods as follows:
public boolean Validate() { 
If (contract.VehicleId() == "")
{
//Vehicle Id must be specified
return checkFailed("@ConWHS:ConWHS45");
}
If (!ConWHSVehicleTable::Exist(contract.VehicleId()))
{
//Vehicle %1 does not exist
return checkFailed(strFmt("@ConWHS:ConWHS46",
contract.VehicleId()));
}
If (contract.VehicleGroupId() == "")
{
//Vehicle group is required
return checkFailed("@ConWHS:ConWHS47");
}
If (!ConWHSVehicleGroup::Exist(
contract.VehicleGroupId()))
{
//Vehicle group %1 does not exist
return checkFailed(strFmt("@ConWHS:ConWHS48",
contract.VehicleGroupId()));
}
return true;
}
public void Run(ConWHSVehicleGroupChangeContract)
{
if(!this.Validate())
{
return;
}
ttsBegin;
this.UpdateVehicleGroup();
ttsCommit;
}
private void UpdateVehicleGroup()
{
ConWHSVehicleTable vehicle =
ConWHSVehicleTable::Find(
contract.VehicleID(), true);

if(vehicle.RecId != 0)
{
vehicle.VehicleGroupId = contract.VehicleGroupId();
vehicle.update();
}
}

The next part of the process is to create the controller class, which is done as follows:

  1. Create a new class called ConWHSVehicleGroupChangeController.
  2. Modify classDeclaration so that it extends SysOperationServiceController.
  3. Next, override the Caption method and change this to return Vehicle group change as a label. This sets the caption, if it is added to a batch queue.
  4. Do the same for the parmDialogCaption method; this sets the title of the dialog that the framework creates from the data contract.
  5. Finally, we will need an entry point, which is a main method. The method should be created as per the following lines of code:
public static void main(Args _args) 
{
ConWHSVehicleGroupChangeController controller;

controller = new ConWHSVehicleGroupChangeController(
classStr(ConWHSVehicleGroupChange),
methodStr(ConWHSVehicleGroupChange,
Run),
SysOperationExecutionMode::Synchronous);
controller.startOperation();
}
  1. Save the changes and create Action Menu Item in our project.
  2. Name the menu item as ConWHSVehicleGroupChangeController and set the Object Type property to Class and the Object property to ConWHSVehicleGroupChangeController.
  3. Add this to the PeriodicTask submenu of the ConWHSVehicleManagement menu and build the project.
..................Content has been hidden....................

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