How to do it...

To create a workflow approval, follow these steps:

  1. Add a new item to the project by selecting Business Process and Workflow from the left-hand list, and then Workflow Approval from the right. Enter ConWHSVehApprWF as the Name and click on Add.
  2. Complete the Workflow Approval dialog as shown here:
  1. Click on Next.
  2. You will be presented with all of the elements the wizard will create for us, reminding us again why the limit is 20 characters and also why the naming is important. Click on Finish.
  3. Open the new ConWHSVehApprWF workflow approval, expand the Outcomes node, and note that the system has associated a workflow event handler class with Approve, Reject, and RequestChange. To complete this element, complete the Label and HelpText properties on the root ConWHSVehApprWF node element. The workflow designer will need this to identify the correct workflow.
  4. There will be five new Action Menu Items created, prefixed with the with approval name, ConWHSVehApprWF. These are suffixed with Approve, DelegateMenuItem, Reject, RequestChange, and ResubmitMenuItem. For each of these, set the Label and Help Text properties with a suitable label, for example:

Menu item

Label

Help text

Approve

Approve

Approve the new vehicle request

DelegateMenuItem

Delegate

Delegate this approval to a colleague

Reject

Reject

Reject the new vehicle request

RequestChange

Revise

Send the request back for revision

ResubmitMenuItem

Resubmit

Resubmit the new vehicle request

Create the labels using names and not numbers, as we will reuse these labels in other areas.
As well as menu items, it also created an event handler class, which is named based on the workflow approval, suffixed with EventHandler. This class will implement seven interfaces, which enforce that a method is implemented, one per event type.
  1. Open the work event handler class, ConWHSVehApprWFEventHandler, and alter the class declaration so that it extends ConWHSVehWFBase.
  2. This class implements the WorkflowElementDeniedEventHandler interface, even though we chose not to in the creation dialog; remove this from the list.
  3. Then, locate the denied method and delete it.
  4. We now need to write some code for each method that was generated for us with a TODO. The sample code to write for each method is as follows:
public void started(WorkflowElementEventArgs _workflowElementEventArgs) 
{
WorkflowContext context;
context =
_workflowElementEventArgs.parmWorkflowContext();
if(this.ValidateContext(context))
{
ConWHSVehicleStatusHandler::SetStatus(
context.parmRecId(),
ConWHSVehApprStatus::InReview);
}
}
  1. Follow this pattern for each method using the following table to determine which status to set:

Element

Method

Waiting

started

InReview

created

Approved

completed

Rejected

returned

Revise

changeRequested

Draft

cancelled

  1. For the created method, the input parameter is a different type; simply change the method as follows:
public void created(WorkflowWorkItemsEventArgs _workflowWorkItemsEventArgs) 
{
WorkflowContext context;
WorkflowElementEventArgs workflowArgs;
workflowArgs =
_workflowWorkItemsEventArgs.parmWorkflowElementEventArgs();
context = workflowArgs.parmWorkflowContext();
if(this.ValidateContext(context))
{
ConWHSVehicleStatusHandler::SetStatus(
context.parmRecId(),
ConWHSVehApprStatus::InReview);
}
}
  1. In the previous recipe, we wrote a method to determine if the workflow did anything that was used to reset the workflow should nothing have been done when the workflow type completed. Open the ConWHSVehWFBase class and alter the method as follows:
public boolean CanCompleteWF(WorkflowContext _context) 
{
ConWHSVehicleTable vehicle;
select RecId from vehicle
where vehicle.RecId == _context.parmRecId();
boolean canComplete;
if (vehicle.RecId != 0)
{
switch (vehicle.Status )
{
case ConWHSVehApprStatus::Approved:
case ConWHSVehApprStatus::Rejected:
canComplete = true;
default:
canComplete = false;
}
}
return canComplete;
}
  1. The final piece of code to write is the resubmission code. A template was created for us, so open the ConWHSVehAppWFResubmitActionMgr class.
  2. In the main method, remove the TODO comment and write the following code snippet:
public static void main(Args _args) 
{
// The method has not been called correctly.
if (_args.record().TableId !=
tablenum(ConWHSVehicleTable)
|| _args.record().RecId == 0)
{
throw error(strfmt("@SYS19306", funcname()));
}
//Resubmit the same workflow, Workflow handles
// resubmit action
WorkflowWorkItemActionManager::main(_args);
// Set the workflow status to Submitted.
ConWHSVehicleStatusHandler::SetStatus(
_args.record().RecId,
ConWHSVehApprStatus::Waiting);

_args.caller().updateWorkflowControls();
}
  1. Open the ConWHSVehApprWF workflow approval, select the Deny outcome, and change the Enabled property to No.
  2. Finally, open the workflow type and then right-click on Supported Elements node. Select New Workflow Element Reference and set the properties as follows:

Field

EDT / Enum

Description

Element Name

ConWHSVehApprWF

This is the element's name

Name

ApprovalVehicle

This is a short version of the name, prefixed with the type

Type

Approval

This is the workflow element's type

  1. Save and close all code editors and designers and build the project. Don't forget to synchronize, as we have added a new field.
..................Content has been hidden....................

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