Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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.
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
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.
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
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.
China=Group1
Mexico=Group2
For your reference, that's what I did similar in our system.
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... 🙂
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);