cancel
Showing results for 
Search instead for 
Did you mean: 

How to implemnt a process with back step flow ??

lobnakh
Champ in-the-making
Champ in-the-making
Hello Everybody!!
I have to implement a process with a gateway with three outgoing conditional flows : 2 flows going to the End event, and the other is going back to the first task. How can i implement this at runtime : when the execution reaches this task : all the process have to be repeated !
Have you any idea how can i implement this !!! Thanks in advance.
8 REPLIES 8

hari
Star Contributor
Star Contributor
Hi,

I didn't get your question here. But with what I understood, you will have to set a condition on the 2 conditional flows and set the once back as a default flow. So when both the conditions fail, the process will get back to step 1 and proceed.

jbarrez
Star Contributor
Star Contributor
Can't you add a sequence flow that goes to the beginning of the process?
What do you mean with 'at runtime' ?

lobnakh
Champ in-the-making
Champ in-the-making
Hello,
I would like to say by 'at runtime' , in my java code : after starting my process instance, i must to querry the tasks for example :Task task1=taskService.createTaskQuery().singleResult();
taskService.complete(task1.getId());
And so on, until querriying all the process tasks.
in the case of the outgoing flow of the gateway, which goes back to the first task, surely all the process will be repeated(there are variables that will be changed , so it is not an infinite loop) ! My question is how can i implement the section of code that will be repeated .How can i optimise my code !!
I wish i was more clear in my response. Thank you

jbarrez
Star Contributor
Star Contributor
I'm not yet following: are you looking for the BPMN to do this (if so, simply loop back to the first step, using exclusive gateways) or how to query this in java?

lobnakh
Champ in-the-making
Champ in-the-making
Exactly, how to query this in java ?? can i use a recursive function !!

lobnakh
Champ in-the-making
Champ in-the-making
Hello ,
I tried to use a recursive function but i had an error to handle !!To better understand my problem, please check my java code attached here.
the error is : org.activiti.engine.ActivitiException: Query return 2 results instead of max 1
PS : when the second condition in the loop if is true, the function simpleProcessTest() is called, in this line :
Task task1 = taskService.createTaskQuery().singleResult();
The exception is thrown : It finds two tasks named : "créer une demande de congé"
I don't understand this replication, because the first task as named , is already completed.
Can somebody help me to solve this problem please ??

jbarrez
Star Contributor
Star Contributor
You are calling your test function again. Which means these lines get execution again:

repositoryService.createDeployment().addClasspathResource("Cong�sbpmn20.xml").deploy();
ProcessInstance pi= runtimeService.startProcessInstanceByKey("simpleProcess");

You are redeploying your process definition and starting a new process instance.
You now have

* 1 process instance looped back to task 1
* 1 new process instance that is in task 1

Hence why the query says you have two results, which is correct.

To fix this, you need to extract this in separate methods, not reuse your test method again.

lobnakh
Champ in-the-making
Champ in-the-making
Thanks! I will try it Smiley Happy