Making Workflow Memo field required when canceling or rejecting

Another of the features usually requested by clients is to make the Workflow Memo field required when you cancel or reject a workflow assignment. This post describes the steps to implement this feature.



The first step is to override the psdi.workflow.WFInstance MBO. Create the 4 classes required for a customized MBO.

After generating the 4 classes edit your WFInstance class and override the completeWorkflowAssignment(int,int,String) method.

The method code should be something like this. In this example I'm making the memo field required when the action is either WO CANCEL or WO REJECT.

  /**
   * Overriden method to implement empty memo validation when canceling or
   * rejecting a WO.
   *
   */
  public void completeWorkflowAssignment(int assignment, int action, String memo)
      throws RemoteException, MXException {
    String wfID = this.getMboValueData("WFID").getData();

    String processName = this.getThisProcessName(wfID);
    String actPerformed = this.getActionName(action, processName);
    if (actPerformed.equalsIgnoreCase("WO CANCEL")
        || actPerformed.equalsIgnoreCase("WO REJECT")) {
      if (memo.trim().length() == 0) {
        throw new MXApplicationException("workflow", "MemoEmpty");
      }
    }
    super.completeWorkflowAssignment(assignment, action, memo);
  }


The only problem you'll have is that the getThisProcessName(String) and getActionName(int,String) are private which means you cannot access them, you'll have to copy them to your class. If only they were protected... The MemoEmpty message is a customized message thay you have to add to MAXMESSAGES.

Finally update the class for your WFACTION MBO in database configuration, rebuild and redeploy your EAR.


Best regards,
--
António Jacob Costa

0 comments:

Post a Comment