2 Replies Latest reply on Jun 24, 2010 1:42 PM by Maciej Swiderski

    Find Task by Process Def and group

    Lalit Bhatia Newbie

      Hi,

       

      I guess there are enough APIs available to work on Tasks provided we have UserId.

       

      I faced a situation where I need to find the open Tasks based on a Process Def and a user Group.

       

      I know couple of options If I have a UserId. I can do it by TaskService.findGroupTasks and then filter out tasks using execution Id etc... but unfortunately I don't have access to userId! I could query jBPM schema to find the details but don't want to mix that with APIs.

       

      Any APIs based solution?

       

      Thanks.

        • 1. Re: Find Task by Process Def and group
          Lalit Bhatia Newbie

          A similar situation where If I have Process Instance key/business key and Group and I need to figure out list of Tasks then I guess following piece of code should work -

           

          -------------------------------------------------------------------

               ProcessInstanceQuery piQuery = new ProcessInstanceQueryImpl();
               ProcessInstance pi = piQuery.processInstanceKey(businessKey).list().get(0);

           

                  // find the Task by process instance id and user id - since the task is assigned to user group
                  // user associated with group will also be candidate
               TaskQuery tQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).candidate(userId);

           

          --------------------------------------------------------------------------------------

           

          what do you say guys?

          • 2. Re: Find Task by Process Def and group
            Maciej Swiderski Master

            Hi,

             

            let me tell you first that this is not the optimal way but you asked for API solution. I think you could achieve what you described in following steps:

            1. find tasks for given process definition

             

            taskService.createTaskQuery().processDefinitionId(defId).list()
            

             

            2. Iterate over returned list of tasks and get partcipations for each

             

            taskService.getTaskParticipations(taskId)
            

             

            3. Check returned list of participations based on

             

            participation.getGroupId()
            

            you can filter what groups you trying to find.

             

            That probably should do what you want but not in the best way. You could find related jira issue or create new one to extend API if it comes to querying for tasks.

             

            HTH

            Maciej