cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically assign a list of users as candidate assignees

leealt
Champ in-the-making
Champ in-the-making

How can I set a list users (e.g. in a comma delimited string) as candidate assignees? I am passing the list to the start form with the process-instance API and attempting to use an expression in the candidate property on the user task.

1 REPLY 1

gdharley
Elite Collaborator
Elite Collaborator

For Enterprise Edition, I use the following script task (groovy) code snippet in BP3's Activiti Basic training to demonstrate this exact scenario.

The example uses the userService to get all users and iterate over the result, but you can use the same technique on a comma separated list passed into the process:

import com.activiti.domain.idm.User;
import com.activiti.security.SecurityUtils;

out.println('Start - Init');
User currentUser = SecurityUtils.getCurrentUserObject();
ArrayList idList = new ArrayList();
Long tenantId = currentUser.getTenantId();

List<User> users = userService.getAllUsers(0,999,tenantId);
for (User u : users) {
idList.add(String.valueOf(u.getId()));
}

execution.setVariable('assigneeList', idList);

out.println('End - Init');

Once you have a list of user ids assigned to a process instance variable, simply set the candidate users to reference the list:

If you are using Community Edition, the approach is exactly the same but instead of using userService you would use identityService.

Hope this helps,
Greg