AnsweredAssumed Answered

Using Java Classes for Decisions in a workflow

Question asked by minalbhatte on Mar 20, 2009
Latest reply on Nov 5, 2009 by hyperation
Hi all,

I want to call a java class method form a workflow.
For that i have used a handler tag in decision  to point to a Java class that implements the DecisionHandler interface.
The decide() method of the handler class should performs the logic it needs to and then it should returns the name of the transition to take.

I have added the jar file of my java class at ..\Alfresco\tomcat\webapps\alfresco\WEB-INF\lib  folder.
But when workflow reach the decision state it is not calling the java class  decision() method.

The procesdefinition.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="" name="wf:adhoc">

   <swimlane name="initiator"/>

   <start-state name="start">
      <task name="wf:submitAdhocTask" swimlane="initiator"/>
      <transition name="" to="adhoc"/>

   <swimlane name="assignee">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
   <task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
      <transition name="" to="CheckAvailability">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
              if (wf_notifyMe)
                 var mail = actions.create("mail");
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from =;
                 mail.parameters.text = "It's done";
   <decision name="CheckAvailability"> 
     <handler class="com.sample.decision.sampleDecisionHandler"></handler>   
     <transition name="trDeliver" to="completed"></transition>  
   <task-node name="completed">
      <task name="wf:completedAdhocTask" swimlane="initiator"/>
      <transition name="" to="end"/>
   <end-state name="end"/>

and my java class code:

package com.sample.decision;


import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;

public class sampleDecisionHandler  implements DecisionHandler{
   public String decide(ExecutionContext executionContext) throws Exception { 
      // Code to create a text file
      System.out.println("Hello Inside sampleDecisionHandler ");
      Writer output = null;
       String text = "Inside Workflow - This is a decision";
       File file = new File("C:\\Alfresco\\write.txt");
       output = new BufferedWriter(new FileWriter(file));
       System.out.println("Your file has been written");
       // Go to transition trDeliver
       return "trDeliver";