cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Can a workflow robot assign a participant to a subsequent task?

TomU
23-Emerald III

Can a workflow robot assign a participant to a subsequent task?

Curious if a workflow robot (or transition) could use some custom code to automatically assign a participant to a particular task.  I'd like to decide who to assign a task to (based on some other criteria generated during workflow execution) without anyone having to select this user in advance.  Is this possible?  If so, are there any code snippets out there that might help show how to do this?  Thanks.

8 REPLIES 8
JacobH
5-Regular Member
(To:TomU)

Hi TomU,

 

Did you ever find a solution to this problem? I have a similar requirement for my workflow.

 

Thanks.

This is very doable.

Can you give the big picture/use case?

David

TomU
23-Emerald III
(To:d_graham)

Essentially automatic task routing based on the location of the user who created a promotion request.  If user's location attribute = "China" then assign upload task to user 'A', else if user's location attribute = "Mexico" then assign upload task to user 'B', etc.  Certain tasks are 'automatic' and happen behind the scenes and I don't want the PR creators to have to manually assign all these other participants when they will always be the same for everyone at the same location.

d_graham
16-Pearl
(To:TomU)

Tom,

 

This is very doable.  I can set it up such that once the code is in place an Admin can change who is user A, user B, etc  as well as add more locations (I assume they all could change over time) without any changes to the code or the workflow and everything will still work.

 

Call me to discuss.

 

David

 

 

TomU
23-Emerald III
(To:d_graham)

I'd have the roles/groups pre-defined, so the workflow would just need to select which role/group to assign a task based on some attribute of the workflow (promotion request) creator.

SEANPAN
6-Contributor
(To:TomU)

  1. Define a properties file, which will be similar as below

    China=Group1

    Mexico=Group2

  2. Create group1 & group2, and add users into them.
  3. Add code to get the group based on the property defined in #1, and then add users within the group into the role you from the team.

For your reference, that's what I did similar in our system.

 

TomU
23-Emerald III
(To:SEANPAN)

Correct, but I have no idea what the code looks like to actually assign users to a task.  That's why I was asking for code snippets...  🙂

SEANPAN
6-Contributor
(To:TomU)

try below code snippet, and make changes on according to your business. 

 

/**
* Below snippet will get the defined group
*/
String propertiesPath = "ext.test.workflowconfig";
String key = "China";
String groupName = "";
ResourceBundle resourceBundle = ResourceBundle.getBundle(propertiesPath);
if(resourceBundle.containsKey(key)) {
groupName = resourceBundle.getString(key);
}

/***
* Below snippet will get the group name
*/
WTGroup wtgroup = null;
QuerySpec querySpec = new QuerySpec(WTGroup.class);
querySpec.appendWhere(new SearchCondition(WTGroup.class, WTGroup.NAME, SearchCondition.EQUAL, groupName, false), new int[] {0});
for(QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec)querySpec); queryResult != null && queryResult.hasMoreElements();)
wtgroup = (WTGroup)queryResult.nextElement();

/**
* Get users from the group and put into a ArrayList
*/
ArrayList<WTUser> members = new ArrayList<WTUser>();
Enumeration<?> member = wtgroup.members();
while (member.hasMoreElements()) {
WTPrincipal principal = (WTPrincipal) member.nextElement();
if (principal instanceof WTUser)
members.add((WTUser) principal);
}

/**
* Add users to roles in the team.
*/

TeamManaged teamManaged = null; // here you can cast your primaryBusinessOjbect into this teamManaged
TeamReference teamRef = teamManaged.getTeamId();
Team team = (Team)teamRef.getObject();
Role role = Role.toRole("roleName");
for(int i =0; i <members.size(); i ++) {
WTPrincipal wtprincial = members.get(i);
team.addPrincipal(role, wtprincial);
}
team = (Team)PersistenceHelper.manager.refresh(team);

Announcements