7 Replies Latest reply on Nov 23, 2016 12:17 PM by Donato Marrazzo

    Dynamic User Task assignment

    Franck cdsosi Newbie

      Hi community,

       

      I am digging into jBPM5 and I have a question dealing with User Task Assignment. I went through several posts about something similar but can not really find an answer to my question...

      The simple and usual way with User Taks is to assign fixed actor(s) or group(s) but if my User Task assignment relies on process data or even event?

      I know you can do something like what is done with Evaluation.bpmn process that is to say use a #{employee} as potentionalOwner and set value of employee variable at process start.

      What would be the solution if I want to assign a User Task to an actor dynamically and based a specific algorithm not just an input field value. Some questions about this situation to get best practise or orientation from community :

      1. Is the use of a variable as potential owner (e.g.  #{employee}) the "good" way to handle this kind of situation?
        • is possible to set it as group id?
        • other way or solution to set dynamically my actor or group ID? Can a User Task actor or group id be left blank and assigned programmatically? => I've read somewhere that when a user Task is reached at process runtime it must assigned to an actor or group at least Administrator. => "By default, jBPM registers a special user with userId "Administrator" as the administrator of each task. You should therefor make sure that you always define at least a user "Adminstrator" when registering the list of valid users at the task service." This sentence let me think that no specific actor can be set when modeling a BPMN process? Is it correct?
      2. Where do I have to plug my specific User Task assignment algorithm? Can it be for instance in an On-Entry script of the User Task or is it too late? If too late is the answer where can I plug it (I hope there is no need to model a specific Task (Service Task) before the User Task?
      3. Is it possible to make a User Task assignment with a Drools rule?
      4. Are there any example available showing these kind of situation?

       

      This makes quite a lot of questions but any help or advices would be appreciated

       

      Kind Regards

        • 1. Re: Dynamic User Task assignment
          Franck cdsosi Newbie

          Bump, to go over spam messages in the forum

          • 2. Re: Dynamic User Task assignment
            Maciej Swiderski Master

            Franck cdsosi wrote:

             

            1. Is the use of a variable as potential owner (e.g.  #{employee}) the "good" way to handle this kind of situation?

            yes, I would say that this is the recommended way of handling dynamic assignment

             

             

            Franck cdsosi wrote:

             

            1. is possible to set it as group id?

            yes, it is treated as any other input parameter that is passed to work item handler. Please note (as Evaluation example illustrates) group assignments is done by specifying data input named GroupId and then you can leave potential owner empty but the construct must be there otherwise parser will complain.

             

             

            Franck cdsosi wrote:

             

            1. other way or solution to set dynamically my actor or group ID? Can a User Task actor or group id be left blank and assigned programmatically? => I've read somewhere that when a user Task is reached at process runtime it must assigned to an actor or group at least Administrator. => "By default, jBPM registers a special user with userId "Administrator" as the administrator of each task. You should therefor make sure that you always define at least a user "Adminstrator" when registering the list of valid users at the task service." This sentence let me think that no specific actor can be set when modeling a BPMN process? Is it correct?

            in general the best practice is to use process variables to refer to the actual assignee (regardless if it's an actor or a group). The other story is on how do you get the proper value for that variable. One and the simplest way is to ask for it when process starts but of course that is not the only way. Since this is process variable it can be set by other tasks (outcome of a service task), it can be set by business rule since you can access process instance in drools rule, can be set when signaling with event data, etc.

            You're right the main requirement for user tasks is that there must be at least one valid business administrator by valid I mean it must be known to the task service. There are two ways of informing task service about users and groups:

            • use UserGroupCallback to load users and groups on demand - recommended
            • prepopulate task service db with all users and groups

             

             

            Franck cdsosi wrote:

            1. Where do I have to plug my specific User Task assignment algorithm? Can it be for instance in an On-Entry script of the User Task or is it too late? If too late is the answer where can I plug it (I hope there is no need to model a specific Task (Service Task) before the User Task?

            you could have a dedicated service that decides about assignment and then use that service in one of the following ways:

            • define a dedicated service task node that will contact the service and get the right assignee based on some input
            • define a rule that will contact the service ....
            • use on entry (not a big fun of putting it there as it's hidden)
            • if the service is not complex and does not have dependencies to outside world you could make it as process variable and when assigning data input/potential owner call a method of that process variable

             

             

            Franck cdsosi wrote:

             

            1. Is it possible to make a User Task assignment with a Drools rule?

             

            as mentioned above, yes it is possible to prepare process variable that will be used to assign people to the task. Most likely it would be possible to use task service/client inside the rule consequence to do the assignment post task creation but I think it is too complex for the case.

            Moreover there is a rule base inside the task service session that has access to task and its data (like potential owners) so defining rules there is yet another option. Please note that to use that I believe it must be initialized differently than what demo setup does so most likely it cannot be shown on demo installation.

             

            HTH

            2 of 2 people found this helpful
            • 3. Re: Dynamic User Task assignment
              neeraj sharma Newbie

              Hi Maciej,

               

              In *.bpmn file, for a human task, if i set GroupId as "HR" and doesnt set actorID. When process reaches that specific Human task, I creates  human task but when I see task table, actualowner_id and createdby_id fields are blank.

               

              Hence, I am not able to  fetch tasks owned by Group "HR"? Can you please help.

               

              Thanks alot

              • 4. Re: Dynamic User Task assignment
                Thomas Setiabudi Expert

                Hi Franck cdsosi,

                 

                You got a great answer from Maciej there.  I just want to add another alternative, which is to create a custom implementation of Human Task Handler.

                 

                this Custom Human Task handler can have the logic on how to resolve the correct actorId or groupId of the task based on some input (you can specify many input parameters for a user task).

                 

                 

                Regards,

                Thomas Setiabudi

                • 5. Re: Dynamic User Task assignment
                  neeraj sharma Newbie

                  Hi Thomas,

                   

                  (issue:-To view TaskList of particular group)

                   

                  what will be best pratisce to see tasklist of particular group,

                   

                  for eg if john wants to  see the tasks assigned to group "HR".

                  Coz there can be a case where there is another user David who is member of both HR and PM group. In order to list HR tasks, if we list user task of David and John. john will be able to see task of HR as well as task of PM which is claimed by David.

                   

                  So how can we handle this situation?

                  • 6. Re: Dynamic User Task assignment
                    Franck cdsosi Newbie

                    Really thanks to Maciej for such a detailed reply, I am gonna have a look at it carefully

                     

                    Thanks also to Thomas for alternative solution. Correct me if I am wrong but the drawback I see with your solution is that if you create a custom implementation of Human Task Handler it applies to all the Human Task Nodes meaning that you must handle all cases in your handler even for different processes (which may not have same requirements) which I found not to be very flexible. You could say to use different sessions but it could become quite complicated to handle if there are many different cases...

                     

                    Franck

                    • 7. Re: Dynamic User Task assignment
                      Donato Marrazzo Newbie

                      Really interesting can you elaborate the concept? or provide a sample?

                      Thank you