Find tasks that are not assigned and have no candidate users nor groups

I want to flag tasks that are neither assigned, nor have candidate users, nor candidate groups.

I have been looking in into taskService.createTaskQuery() but I don’t know how to query for this.

I am ready to resort to an ugly native query involving a join such that rows act_ru_task have null assignee and where the task id does not appear in any row of act_ru_identitylink.task_id_ where the type is candidate but I thought I would ask before going this ugly path in case I have missed something, or someone suggests a more elegant solution that leverages the higher taskService api. Thank you for a beautiful program.

What do you think about

taskService.createTaskQuery().taskUnassigned().list().stream()
    .filter(task -> ((TaskEntityImpl) task).getIdentityLinkCount() == 0)
    .collect(Collectors.toList());

Also ugly but less than the sql based one :smile:

Regards

1 Like

Thank you. Definitely more maintainable.

When using this approach I am concerned whether there are cases when id links of types other than candidate (such as participant or starter) are associated with a task so the identity link count would not be zero even though there are no candidates.

I have seen those types of id links but only associated to process instances and process definitions, never to tasks, so maybe the case I am worried about is impossible.

@selkhlifi, thank yoo for your suggestion. I verified it, and only links of type candidate appear associated to tasks so testing for id_link_count=0 indeed suffices. FWIW, I still ended up using a native query to avoid the postprocessing step, but it is a much cleaner query without join: "SELECT * FROM "+managementService.getTableName(Task.class) + " WHERE assignee_ IS NULL AND id_link_count_ = 0"