cancel
Showing results for 
Search instead for 
Did you mean: 

Howto get both assigned tasks and tasks where use is candidate in one call

xman-berlin
Champ in-the-making
Champ in-the-making
Hi all,

I want to retrieve all tasks that are assigned to a user plus all tasks where the user is a candidate to properly implement paging and sorting. The following scenario should work:
  • Start one process with one simple user task defining candidate groups (group1, group2)
  • Query tasks for user (member of group1) for assigned and candidate tasks: returns the simple unassigned task
  • User claims that task
  • Query tasks for user (member of group1) for assigned and candidate tasks: returns the simple assigned task
I tried different combinations of TaskQuery-Parameters, e.g. taskAssignee+candidateUser or assignee+candidateGroupIn, but the resulting list did not contain the assigned task.

Any help is appreciated,
Best regards,
Torsten
11 REPLIES 11

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Torsten,

e.g.


    TaskQuery query = taskService.createTaskQuery().taskCandidateOrAssigned("kermit");



task candidate in groups

    List<String> groups = Arrays.asList("management", "accountancy");
    TaskQuery query = taskService.createTaskQuery().taskCandidateGroupIn(groups);


Regards
Martin

xman-berlin
Champ in-the-making
Champ in-the-making
Hi Martin,

this works. I thought I already tested it, but obviously not.

Thanks,
Torsten

xman-berlin
Champ in-the-making
Champ in-the-making
Follow up: The function seems to fail for users which were candidates as well. I have the following test case:
  • Start process with a simple task.
  • user1 and user2 are candidates of the task.
  • user1 claims the task.
  • user1 queries tasks by TaskQuery.taskCandidateOrAssigned: returns task1. -> OK
  • user2 queries tasks by TaskQuery.taskCandidateOrAssigned: returns task1. -> FAIL.
I thought that claiming a task removes it from tasklist of other candidates. To prove the failure, I tried to claim the task by user2 but this works as expected -> Activiti throws ActivitiTaskAlreadyClaimedException.

Any hints?

Thanks,
Torsten

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Torsten,

I created jUnit test and you are right.

The way how the query is implemented is:

        <when test="bothCandidateAndAssigned">
          <if test="userIdForCandidateAndAssignee != null">
            and (RES.ASSIGNEE_ = #{userIdForCandidateAndAssignee} or (RES.ASSIGNEE_ is null and I.USER_ID_ = #{userIdForCandidateAndAssignee} or I.GROUP_ID_ IN (select g.GROUP_ID_ from ACT_ID_MEMBERSHIP g where g.USER_ID_ = #{userIdForCandidateAndAssignee} ) ) )
          </if>
        </when>

It means that candidate is taken into account only for tasks without assignee.
Another possibility for you could be to use native query support.

Regards
Martin

xman-berlin
Champ in-the-making
Champ in-the-making
Hi Martin,

I see, the sql statement is just missing the limitation of "RES_ASSIGNEE_ is null" when it checks the group IDs.

I think this is a bug.

Thanks for your help,
Torsten




martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Torsten,

I would say, that limitation is

RES.ASSIGNEE_ is null …..

I think when the task is assigned, it is not fetched into the query for candidates.

I am not sure whether it is bug or not, it could be done by purpose like this.

Regards
Martin

p4w3l
Champ in-the-making
Champ in-the-making
Can you please give a native query solution for the original question: Howto get both assigned tasks and tasks where use is candidate in one call

bam
Champ in-the-making
Champ in-the-making
Hello,

I think that the option "RES.ASSIGNEE_ is null" should be an option in the API of the task query.
I have a similar need, and i'm struggling with it. I see no other choice than native query, which isn't nice..

Or, is there any other way?

Thanks,
Regards.

bam
Champ in-the-making
Champ in-the-making
Please, please, create an option for that use case. We might want to see our tasks and our colleague's !
I forked the repo to edit Task.xml to remove all the references to "RES.ASSIGNEE_ is null", and recompile my own version of the engine.  I hate doing this. I hate it..

Thank you.