TaskQuery returning empty results

Hi Team,

We created a workflow which contains Assignee as well as Candidate Groups. The User tasks are assigning based on the business requirement to individual assignee or to Candidate Groups. As part of completing the User Task we are validating before completing the task. Here is the code to validate whether the task has been assigned to logged in User or the user belongs to any of the assigned Candidate Groups.


String assignee = "assignee@email.com";
List candidateGroups = new ArrayList<>() {{ add("GUID1"); }};
Task task = getTaskService()
	.createTaskQuery()
	.taskId(taskId)
	.or()
		.taskAssignee(assignee)
		.taskCandidateGroupIn(candidateGroups)
	.endOr()
	.initializeFormKeys()
	.singleResult();

The above query is working fine when the Assignee is null and having Candidate Groups. But when the assignee is not null and Candidate Groups is null it is returning empty results.

Thanks
Prabhaker Goli

Because assignee and candidate group will be transformed as and criteria

Hi @aravindhrs,

How can we write a TaskQuery to return either assignee or candidate groups for the Task?. I could not find any examples on returning Tasks assigned to assignee or candidate groups. Please do send me if you have any examples on the above scenario.

Thanks
Prabhaker Goli

From the above query similar to or expression, you can add it for assignee and candidate group

Hi @aravindhrs,

I tried by changing the TaskQuery in the following:


Task task = getTaskService()
            .createTaskQuery()
            .taskId(taskId)
            .or()
                .taskAssignee(assignee)
            .endOr()
            .or()
                .taskCandidateGroupIn(userGroups)
            .endOr()
            .initializeFormKeys()
            .singleResult();

Still the result is returning empty.

Thanks
Prabhaker Goli

Try this one.

Task task = getTaskService()
            .createTaskQuery().active()           
            .or()
                .taskId(taskId)
                .taskAssignee(assignee)
            .endOr()
            .or()
                .taskId(taskId)
                .taskCandidateGroupIn(userGroups)
            .endOr()                
            .singleResult();

The following methods cannot be applied to an OR query: orderBy…(), initializeFormKeys(), withCandidateGroups(), withoutCandidateGroups(), withCandidateUsers(), withoutCandidateUsers().

Read about the or-queries limitations.

Still returning the empty results.