How to setting multi instance gateway expression?

Hello everyone:
I have question for this easy process.

How can I control it to go to the next Task when all is completed or [yes]>3

You can use local variables that exist for each instance of the user task.
Once a task is complete the value is checked by a task listener, which can set a global variable that can be used as a counter for the resutls when all tasks are completed the process moves on and the gateway will check the global counter variable to decide how to move on.

Hi @Leo_Liu , you might also find these two links helpful:


Hi Niall:
it’s my Task-1 task listener code.
it can finish this.

public class TaskListen implements TaskListener {
@Override
public void notify(DelegateTask arg0) {
if(arg0.getEventName().equals(“complete”)) {
DelegateExecution processInstance = arg0.getExecution().getProcessInstance();
if((boolean)arg0.getVariable(“pass”)) {
if(processInstance.getVariable(“count”)==null) {
processInstance.setVariable(“count”, 1);
}else {
int count = (Integer)processInstance.getVariable(“count”);
processInstance.setVariable(
“count”, count + 1);
}
}
}
}
}

Now I think local variables equal to activity instance variables and global variables equal to process instance variables is this concept right?

Hi @Leo_Liu

Your question has come up occasionally so i decided to create a working example. You can find the project here on github. Let me know if it makes sense and solves your problem.

2 Likes

Thanks you so much @Niall
This example is clear to me now.

Hi @Niall
I have a new question
if the process is [ StartEvent -> UserTask1 -> UserTask2(multi instance) -> EndEvent]
How should i know next Task is multi instance and to setting collection in variables by java api.

Sorry, i’m not really sure what you mean by that can you explain in a more detail?

Sorry, English is not my native language, but I will try my best to make you understand my question.

process
like this sample
I can use Rest Api POST/task/{Tasl1 Id}/complete and set UserList in variables to create multi instance on Task2.

Now I use java api to complete Task1 instance and get the exception.
This exception is variables no set UserList

My question :
How should i know next Task is multi instance task.

Can you post up the exact exception that you’re getting and the exact java code you’re running to complete the task.

It’s my code and process



if want to complete task 2 , I need set assigneeList otherwise it get ProcessEngineException: Unknown property used in expression: ${assigneeList}. Cause: Cannot resolve identifier ‘assigneeList’

I can know the next Task is multi instance and setting variables before complete Task2?

Thanks for uploading the code that really helps.
The problem is that you’re not passing in any variables when you complete the task.
You can send variables in like this:

      Map<String, Object> vars = new HashMap<String, Object>();
      vars.put("myVariableName", "ValuableValue")
      taskService().complete(task.getId(), vars);

Hello @Niall ,
I just now faced a same problem of parallel multi-instance. I’m concerned about a race condition in this solution. May I know what you think about it please?