Use of Or/And combination conditions in the task query in Camunda 7

I need to implement this logic in the taskQuery to pull out a task list as :

pull up those tasks which meets one of these conditions :

– either assigned to this user
– or that task is unassigned but belongs to the group that user is part of (based on role )

With the above logic tried :

     taskQuery
              .taskUnassigned().taskCandidateGroupIn(group)
              .or().taskAssignee(assignee).endOr()
     .list();

My list is always empty with the above query. However, if I try separately :

  • taskQuery.taskUnassigned().taskCandidateGroupIn(groups) ----> pulls out right tasks in the list
  • taskQry.taskAssignee(assignee) —> pulls out right tasks in the list

Question:

  • What am I doing wrong in my combined query when using the OR condition?
  • Is there a way to implement “AND” condition so that I can do something like :
     taskQuery
              .or()
                    and().taskUnassigned().taskCandidateGroupIn(group).endAnd()
              .endOr()
             .or()taskAssignee(assignee).endOr()
   .list();

Thanks in advance

Could you try the same without taskUnassigned() as taskCandidateGroupIn by default only selects tasks which are not already assigned to a user

taskQuery.taskCandidateGroupIn(group)
              .or().taskAssignee(assignee).endOr()
     .list();