Assign Task to Groups (must done by the all members)

Hello, I am new in this world.

I like to assign one task to all group members. All members of the group have to complete tasks and I need to check their answers and decide to go or return back.

For example, the group has 10 members.

  1. Question: Are you ok?
  2. Collect all answers. (True and false)
  3. Make a decision with gateway: if more members are feeling ok (if true count bigger than false) go to the next activity, if not end the process.

Problems that I faced:

  • So I assign to task candidate groups, but here if one of the members completes the task so later rest of the members can not see it anymore, and process forward to the next step.

  • I don’t understand multi-instance using in the task, I read the documentation but still, It doesn’t give me any idea for that.

So if you have any solutions pattern or offer please turn light on.

@Oktay_Ibis Refer the below example:

@Slf4j
@Component
public class PrepareCandidatesListDelegate implements JavaDelegate {

	@Override
	public void execute(DelegateExecution execution) throws Exception {
		log.info("Executing PrepareCandidatesListDelegate...");
		Map<String, Object> variableMap = new HashMap<>();
		variableMap.put("usersList", Stream.of("a","b","c","d","e").collect(Collectors.toList()));
		variableMap.put("votingResults", new ArrayList<>());
		execution.setVariables(variableMap);
	}

}

@Slf4j
@Component
public class VoteRegisterListener implements TaskListener {


	@SuppressWarnings("unchecked")
	@Override
	public void notify(DelegateTask delegateTask) {
		log.info("Executing VoteRegisterListener....");
		List<Boolean> votingResults = (List<Boolean>) delegateTask.getVariable("votingResults");
		boolean result = (Boolean) delegateTask.getVariable("approved");
		votingResults.add(result);
		log.info("result: {}, votingResults: {}", result, votingResults);
		delegateTask.setVariable("votingResults", votingResults);
	}

}

@Slf4j
@Component
public class VoteCountingDelegate implements JavaDelegate {

	@SuppressWarnings("unchecked")
	@Override
	public void execute(DelegateExecution execution) throws Exception {
		log.info("Executing voteCountingDelegate....");
		List<Boolean> votingResults = (List<Boolean>) execution.getVariable("votingResults");
		log.info("votingResults: {}", votingResults);
		long votedCount = votingResults.stream().filter(v -> v.booleanValue() == Boolean.TRUE.booleanValue()).count();

		VariableMap variableMap = Variables.createVariables().putValue("totalCount", votingResults.size())
				.putValue("threshold", votingResults.size() / 2).putValue("approvedCount", votedCount)
				.putValue("rejectedCount", votingResults.size() - votedCount);

		execution.setVariables(variableMap);
	}

}

BPMN File used for testing: votingprocess.bpmn (6.6 KB)

@aravindhrs Thanks for reply.

Where is correct please write these code blocks? Is there any chance to handle this, only in the bpmn?

Yes. You can do this without code. I just used this code to manipulate data.

So do you have any idea how can I do ? @aravindhrs

So I found the solution with a parallel sub-process.
Here is the solution:
first created script task:
var identity = execution.getProcessEngineServices().getIdentityService(); var members = identity.createUserQuery().memberOfGroup(grupId).list(); execution.setVariable("varName",members); var voteList = []; execution.setVariable("voteList",voteList);

After that creating a parallel task:

  • Collection is VarName
  • element Variable is element (it can be any name, just point one of the member of array)
  • Assignee: ${element}

So add Task Listeners for the counting result of each member’s task:
var list = task.execution.getVariable("voteList"); list.push(voted) // voted coming from user task form field. task.execution.setVariable("voteList", list);