2 Replies Latest reply on May 17, 2006 7:08 AM by Sven Binnewies

    assign a task instance at runtime

    Sven Binnewies Newbie

      Hi there,

      how can I assign a task instance to a specific user at runtime? The user is not known at the process definition, so I can't write the user (actorID) into an assigment handler. So is there a way to assign users to task istcanes dynamicly? Via assignment handlers, as pooled actors, as jbpm API calls in the source code or something else? Thanks in advance.

      regards

        • 1. Re: assign a task instance at runtime
          Jeff Gordon Newbie

          You can do anything in an assignment handler to look up user id's or set an assigned group to get tasks into a task list, something like this will set a Pooled Actor but not assign the task:

          public class GroupAssignmentHandler implements AssignmentHandler {
           private static final long serialVersionUID = 1L;
           private static final Logger log = Logger.getLogger(GroupAssignmentHandler.class.getName());
           private String groupName;
          
           public void assign(Assignable assignable, ExecutionContext executionContext) {
           log.debug("Assigning to group "+groupName);
           Set group = new HashSet();
           group.add(new PooledActor(groupName));
           if (assignable instanceof TaskInstance) {
           ((TaskInstance)assignable).setPooledActors(group);
           } else if (assignable instanceof SwimlaneInstance) {
           ((SwimlaneInstance)assignable).setPooledActors(group);
           } else {
           assignable.setPooledActors(new String[] {groupName});
           }
           }
          
          }
          



          Then each task can be retrieved with:

          List tasks = jbpmContext.getTaskMgmtSession().findPooledTaskInstances(groupName);
          if (tasks!=null && tasks.size()>0) {
           // obviously you'd want to have a loop here and check to see if this task is already assigned...
           TaskInstance task = (TaskInstance)tasks.get(0);
           taskInstance.setActorId(userId);
          }
          

          You'd want to save and close your jbpmContext right after this to get your changes committed.

          • 2. Re: assign a task instance at runtime
            Sven Binnewies Newbie

            I will try that, many thanks!