cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute more than one task in Activiti engine

marwahussein
Champ in-the-making
Champ in-the-making
Hello,
I am trying to execute a simple business process within Activiti. I have four user tasks
I defined the user tasks in the XML file as follows:


<userTask id="evaluateLoanRequest" name="Evaluate loan request" >
<userTask id="acceptloan" name="Accept Loan"/>

in the main code I tried to execute the first user with those commands  task and it was executed successfully

[java]
taskService.createTaskQuery().singleResult();
taskService.delegateTask(taskService.createTaskQuery().singleResult().getId(), "Marwa");
taskService.claim(taskService.createTaskQuery().singleResult().getId(), null);
taskService.claim(taskService.createTaskQuery().singleResult().getId(), "Alaa");
taskService.complete(taskService.createTaskQuery().singleResult().getId(), processVariables);
[/java]

when I am trying to execute the second user task it doesn't work

[java]
taskService.createTaskQuery().taskDefinitionKey("acceptloan");
[/java]

I don't know what is the problem.. any help will be appreciated
9 REPLIES 9

plehal
Champ in-the-making
Champ in-the-making
It depends on how are tasks are getting created or completed. From your xml it does not show how the workflow tasks are arranged. Does the second task even get created?

marwahussein
Champ in-the-making
Champ in-the-making
I control the creation and completion of the tasks from the main code not from the XML
how I can arrange the workflow of the tasks from the XML file ?

jbarrez
Star Contributor
Star Contributor
The second user task must follow after the first: a sequence flow between the two must be defined. Is that the case?

marwahussein
Champ in-the-making
Champ in-the-making
there is a sequence flow between the first user task and the second
here is the full XML definition


<process id="loanrequest_withespertest" name="Process to handle a loan request with Esper">
           
  <startEvent id="theStart"/>
  <sequenceFlow sourceRef="theStart" targetRef="evaluateLoanRequest" />
  <userTask id="evaluateLoanRequest" name="Evaluate loan request" >
                   
                     <extensionElements>
                         <activiti:taskListener event="create" class="org.bpmnwithactiviti.popevent.test.MyTaskCreateListener" />
                    <activiti:taskListener event="assignment" class="org.bpmnwithactiviti.popevent.test.MyTaskCreateListener" />
                    <activiti:taskListener event="complete" class="org.bpmnwithactiviti.popevent.test.MyTaskCreateListener" />
                 <!–   <activiti:taskListener event="take" class="org.bpmnwithactiviti.popevent.test.SuspendListener" /> –>
                     </extensionElements>
                   
                    <humanPerformer>
                         <resourceAssignmentExpression>
                             <formalExpression>Galal</formalExpression>
                         </resourceAssignmentExpression>
                     </humanPerformer>
                    
                </userTask>
               
               
               
                <sequenceFlow sourceRef="evaluateLoanRequest" targetRef="exclusivegateway1" />
                <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" />
               
                <sequenceFlow  sourceRef="exclusivegateway1" targetRef="acceptloan"/>
                <sequenceFlow  sourceRef="exclusivegateway1" targetRef="rejectloan"/>
               
                <userTask id="acceptloan" name="Accept Loan"/>
                <userTask id="rejectloan" name="Reject Loan"/>
               
                <sequenceFlow  sourceRef="acceptloan" targetRef="exclusivegateway2"/>
                <sequenceFlow  sourceRef="rejectloan" targetRef="exclusivegateway2"/>
               
                <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"/>
               
                <sequenceFlow  sourceRef="exclusivegateway2" targetRef="preparenotificationletter"/>
               
                <userTask id="preparenotificationletter" name="Prepare Notification Letter">
                <extensionElements>
                         <activiti:taskListener event="create" class="org.bpmnwithactiviti.popevent.test.MyTaskCreateListener" />
                    <activiti:taskListener event="assignment" class="org.bpmnwithactiviti.popevent.test.MyTaskCreateListener" />
                    <activiti:taskListener event="complete" class="org.bpmnwithactiviti.popevent.test.MyTaskCreateListener" />
                     </extensionElements>
                   
                     <humanPerformer>
                         <resourceAssignmentExpression>
                             <formalExpression>Amr</formalExpression>
                         </resourceAssignmentExpression>
                     </humanPerformer>
                    
                </userTask>
               
  <sequenceFlow sourceRef="preparenotificationletter" targetRef="theEnd" />
  <endEvent id="theEnd" />
</process>

all I need is to execute the first user task then the second one but when I try to execute the second one the engine didn't do anything

trademak
Star Contributor
Star Contributor
Why do you have 2 outgoing sequence flows with no condition after the first exclusive gateway? Using an exclusive gateway without any conditions on the outgoing sequence flow doesn't make much sense. Did you try to remove the exclusive gateway and go from the "evaluateLoanRequest" user task to the "acceptloan" directly? Does it work then?

Best regards,

I removed the exclusive gateway and went from the "evaluateLoanRequest" user task to the "acceptloan" directly and the same problem is still there
this is the code I wrote in the main class:



taskService.createTaskQuery().singleResult();
taskService.delegateTask(taskService.createTaskQuery().singleResult().getId(), "Marwa");
taskService.claim(taskService.createTaskQuery().singleResult().getId(), null);
taskService.claim(taskService.createTaskQuery().singleResult().getId(), "Alaa");
taskService.complete(taskService.createTaskQuery().singleResult().getId(), processVariables);

taskService.createTaskQuery().taskDefinitionKey("acceptloan");

is there something wrong ?

jbarrez
Star Contributor
Star Contributor
No, that should work. And we have plenty of unit tests that test that. Can you upload your whole unit test (java + xml)?

marwahussein
Champ in-the-making
Champ in-the-making
I uploaded here the classes, the xml and the main code 

jbarrez
Star Contributor
Star Contributor
That has a alot of Esper logic in it … which makes it impossible for me to test :s