cancel
Showing results for 
Search instead for 
Did you mean: 

Want to use custom class by <activiti:taskListener

rakesh_world86
Champ in-the-making
Champ in-the-making
This is a simple example , where custom assignment via task listner is working .
Find the word "testserlvet.testclass" , this is a custom class , that this is working..


XML code

<process id="messageProcess" name="My Message" isExecutable="true">
    <startEvent id="startevent1" name="Start">
    </startEvent>
    <userTask id="usertask1" name="Approve (I am in Kartarpur)" activiti:assignee="kermit">
      <documentation>I am in Kartarpur</documentation>
      <extensionElements>
       <activiti:taskListener event="create" class="testserlvet.testclass" />
     </extensionElements>
    </userTask>
    <sequenceFlow id="flow4" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <userTask id="usertask2" name="Approve (I am in Jalandhar)" activiti:assignee="kermit">
      <documentation>I am in jalandhar</documentation>
    </userTask>
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <userTask id="usertask3" name="Approve (I am in Amritsar)" activiti:assignee="kermit">
      <documentation>I am in Amritsar</documentation>
    </userTask>
    <sequenceFlow id="flow6" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow8" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
  </process>




// testserlvet.testclass

package testserlvet;
import java.io.File;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
public class testclass implements TaskListener {
   public void notify(DelegateTask delegateTask) {
      System.out.println("printed ***********************************************");
          delegateTask.setAssignee("fozzie");
        File f = null;
         boolean bool = false;

         try{
            f = new File("c:\\activiti.txt");
            bool = f.createNewFile();
            System.out.println("File created: "+bool);
            f.delete();
            bool = f.createNewFile();
            System.out.println("File created: "+bool);
         }catch(Exception e){
            e.printStackTrace();
         }
     }
}





now , this is second xml , where custom assignment via tasklistner is not working.
pls find in testserlvet.testclass, why this is not working ..  testserlvet.testclass is same class shown above.. i have tried a lot but unable to run.. pls help me..

<process id="ApplyForLicense" name="Apply for license" isExecutable="true">
    <startEvent id="request" activiti:initiator="employeeName">
      <extensionElements>
        <activiti:formProperty id="licenseHolderName" name="licenseHolderName" type="string" required="true"></activiti:formProperty>
      </extensionElements>
    </startEvent>
    <sequenceFlow id="flow1" sourceRef="request" targetRef="handleRequest"></sequenceFlow>
    <userTask id="handleRequest" name="Handle license request" activiti:candidateGroups="inbox,management">
      <documentation>${licenseHolderName} has applied for license.</documentation>
      <extensionElements>
        <activiti:formProperty id="licenseApproved" name="Do you approve this license" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="Comments" name="Comments" type="string"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow2" sourceRef="handleRequest" targetRef="requestApprovedDecision"></sequenceFlow>
    <exclusiveGateway id="requestApprovedDecision" name="Request approved?"></exclusiveGateway>
    <sequenceFlow id="flow3" sourceRef="requestApprovedDecision" targetRef="sendApprovalMail">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${licenseApproved == 'true'}]]></conditionExpression>
     
    </sequenceFlow>
    <userTask id="sendApprovalMail" name="Send confirmation e-mail">
      <documentation>Your manager has approved your license.</documentation>
      <extensionElements>
        <activiti:taskListener event="assignment" class="testserlvet.testclass"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow4" sourceRef="sendApprovalMail" targetRef="theEnd1"></sequenceFlow>
    <endEvent id="theEnd1"></endEvent>
    <sequenceFlow id="flow5" sourceRef="requestApprovedDecision" targetRef="adjustLicenseRequestTask">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${licenseApproved == 'false'}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="adjustLicenseRequestTask" name="Reject License Approval">
      <documentation>Your manager has disapproved your license request . Reason: ${Comments}</documentation>
    </userTask>
    <endEvent id="theEnd2"></endEvent>
    <sequenceFlow id="flow6" sourceRef="adjustLicenseRequestTask" targetRef="theEnd2"></sequenceFlow>
  </process>
5 REPLIES 5

balsarori
Champ on-the-rise
Champ on-the-rise
The assignment event is fired when the task is assigned to someone. In your second xml, the user task doesn't have an assignee set. Did you set the task's assignee somewhere else in your code?

rakesh_world86
Champ in-the-making
Champ in-the-making
XML code

but now i have removed  activiti:assignee="kermit" from xml , then custom event is firing without assign task..

<code>
<process id="messageProcess" name="My Message" isExecutable="true">
    <startEvent id="startevent1" name="Start">
    </startEvent>
    <userTask id="usertask1" name="Approve (I am in Kartarpur)">
      <documentation>I am in Kartarpur</documentation>
      <extensionElements>
     <activiti:taskListener event="create" class="testserlvet.testclass" />
   </extensionElements>
    </userTask>
    <sequenceFlow id="flow4" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <userTask id="usertask2" name="Approve (I am in Jalandhar)" activiti:assignee="kermit">
      <documentation>I am in jalandhar</documentation>
    </userTask>
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <userTask id="usertask3" name="Approve (I am in Amritsar)" activiti:assignee="kermit">
      <documentation>I am in Amritsar</documentation>
    </userTask>
    <sequenceFlow id="flow6" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow8" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
  </process>
</code>

balsarori
Champ on-the-rise
Champ on-the-rise
According to your code usertask1 should be assigned to fozzie. So, your code gets called but the task doesn't get assigned to fozzie, is that what you mean?

What version of Activiti are you using?

rakesh_world86
Champ in-the-making
Champ in-the-making
i am using 5.17 version of activiti.

yes , my code gets called but the task doesn't get assigned to fozzie or some one.

what does it mean , that According to my code usertask1 should be assigned to fozzie , if there is no assignee for this task.



jbarrez
Star Contributor
Star Contributor
Your task listener is hooked in  on the assignment event

<code>
event="assignment"
</code>

But you haven't set an assignee, so the event is never fired.

In your original code you are using the 'create' event instead of the 'assignment' event.