How to do it...

To hook up the state machine to a workflow task, follow these steps:

  1. Open the ConWHSVehWFInsp workflow task.
  2. Set the Canceled State Machine property to InspStateMachine.
Yes, this is spelled Canceled, but it is more than compensated by the clever way it has determined the list of valid state machines.
  1. Set the Canceled State Machine Target State property to Waiting; we won't be allowed to use NotInspected. Due to this being the state machine's initial state, it will let you set this value, but the state machine will reject the change.
  2. Set the Started State Machine property to InspStateMachine, and the Started State Machine Target State property to Waiting.
You will also need to allow the Waiting state to transition directly to Complete. Don't forget to click on Generate to regenerate the state machine class.
  1. Select the Completed outcome, set the State Machine property to InspStateMachine, and the set State Machine Target State property to Complete.
  2. Since we now have two ways to set the status, we will (as a short term fix) disable the status update code that set the status in the SetStatus method of the ConWHSVehInspStatusHandler class. Open this class and remove the line that set the InspStatus field.
We will update this code properly in the There's more... section.
  1. Upon testing this, we will find that the task completed sets the comment correctly, but the status doesn't change to completed. The reason is because the workflow events fire last, so the state machine validation rejected the update because the comment was not yet set. We need to update our validation logic so that it only runs when triggered from the form. Alter the Validate method of the ConWHSVehInspStatusHandler class so that it reads as follows:
public boolean Validate() 
{
switch (toStatus)
{
case ConWHSVehInspStatus::Complete:
if (vehicle.InspComment == ''
&& FormDataUtil::isFormDataSource(vehicle))
{
//The field %1 must be filled in"
DictField field = new DictField(
tableNum(ConWHSVehicleTable),
fieldNum(ConWHSVehicleTable,
InspComment));
return checkFailed(strFmt(
"@SYS110217",
field.label()));
}
break;
}
return true;
}
The highlighted code checks if the record buffer is a form data source; if the code was called from within workflow, the table will not be linked to a form's data source.
  1. Build and test the workflow; all should work correctly.
..................Content has been hidden....................

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