How to do it...

To create a handler class to add further validation to the state machine, follow these steps:

  1. Open the ConWHSVehicleInspStatusHandler class and add the following piece of code:
public ConWHSVehInspStatus fromStatus; 
public ConWHSVehInspStatus toStatus;
public ConWHSVehicleTable vehicle;

public boolean Validate()
{
switch (toStatus)
{
case ConWHSVehInspStatus::Complete:
if (vehicle.InspComment == '')
{
DictField field = new DictField(
tableNum(ConWHSVehicleTable),
fieldNum(ConWHSVehicleTable,
InspComment));

//The field %1 must be filled in"
return checkFailed (strFmt(
"@SYS110217",
field.label()));
}
break;
}
return true;
}

public void run()
{
if(toStatus == fromStatus)
{
return;
}
if(this.Validate())
{
switch (toStatus)
{
case ConWHSVehInspStatus::Complete:
Timezone tz = DateTimeUtil::
getClientMachineTimeZone();
ConWHSVehInspDate inspDate;
inspDate = DateTimeUtil::getSystemDate(tz);
vehicle.InspDate = inspDate;
break;
}
}
else
{
vehicle.InspStatus = fromStatus;
}
}
There is nothing new about the preceding code, except that we don't (and must not) call update on the record. It is just a validation class that will stop the transition if the comment is blank.
  1. The code to tie it to the transition delegate is as follows:
[SubscribesTo(classStr(ConWHSVehicleTableInspStateMachine),  
delegateStr(
ConWHSVehicleTableInspStateMachine, Transition))]
public static void HandleTransition(
ConWHSVehicleTableInspStateMachineTransitionEventArgs
_eventArgs)
{
ConWHSVehicleInspStatusHandler handler;
handler = new ConWHSVehicleInspStatusHandler();

handler.vehicle = _eventArgs.DataEntity();
handler.fromStatus = _eventArgs.ExitState();
handler.toStatus = _eventArgs.EnterState();
handler.Run();
}
..................Content has been hidden....................

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