Skip to main content
23-Emerald IV
June 5, 2019
Question

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

  • June 5, 2019
  • 1 reply
  • 3960 views

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.

1 reply

6-Contributor
August 10, 2021

Hi TomU,

 

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

 

Thanks.

18-Opal
August 10, 2021

This is very doable.

Can you give the big picture/use case?

David

1-Visitor
August 13, 2021

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);