Dinesh
Dinesh

Reputation: 180

How to assign a task to a group?

How can I assign a task to a user group in activiti. To a single user it can be done using below code.

taskService.setAssignee(taskId, userId);

But how can we assign a single task to a group, which can be picked by any user belong to that group.

Upvotes: 2

Views: 1476

Answers (1)

Martin Grofčík
Martin Grofčík

Reputation: 194

Use TaskService:

      /**
   * Convenience shorthand for {@link #addGroupIdentityLink(String, String, String)}; with type {@link IdentityLinkType#CANDIDATE}
   * 
   * @param taskId
   *          id of the task, cannot be null.
   * @param groupId
   *          id of the group to use as candidate, cannot be null.
   * @throws ActivitiObjectNotFoundException
   *           when the task or group doesn't exist.
   */
  void addCandidateGroup(String taskId, String groupId);

When you add candidate group, you can fetch the task by:

  taskService.addCandidateGroup(task.getId(), "sales");
  assertNotNull(taskService.createTaskQuery().taskCandidateGroup("sales").singleResult());

For more info check org.activiti.engine.test.api.task.TaskServiceTest#testDeleteTaskIdentityLink in activiti source.

Upvotes: 2

Related Questions