Skip to main content
1-Visitor
March 3, 2013
Question

Programmatically assign a task participant

  • March 3, 2013
  • 7 replies
  • 3824 views

I am trying to set up a participant for a task based on a workflow variable. I have created a wt.project.role variable that I a setting at the start of activity or the end of the previous activity. The Role is getting populated correctly, however there is no user getting resolved to this role from the team and so the task goes to the author.

Is there a way to do this? WC 10.0

7 replies

1-Visitor
March 4, 2013

Hi Jason,

Please assign the ROLE into a global variable(wt.project.role) and mention the same variable into the Activity by selecting --> Participants tab-->remove any assigned role and add Variables.

Hope this will work for You.

BR

MK Ramanathan

jasonb11-VisitorAuthor
1-Visitor
March 4, 2013

HI MK,

I have created an attribute on the change object that I am using to populate a wt.project.role global variable and then I use that variable in the Participants tab as you have suggested. However, when the task gets assigned, the role is set to the desired role, however the assignee is set to the author, not the person that is in the team role.

Thanks,

Jason

1-Visitor
March 4, 2013

I wouldn't bother with trying to assign an activity through the use of a variable.

Try setting up your activity to go to your specified Role the way you normall would. Before the activity starts (in the COMPLETE transition of the predecessor WfActivity or in a WfExpression), populate the Role on your primaryBusinessObject's Team.

1-Visitor
March 14, 2013

Hi Jason,

We had a similar problem. We needed to 'carry over' partipants into the new workflow process. This was because the same users would always be assigned against any new work carried out on the document/part. The following code could be adapted to filter out which roles will be carried over.

We call the following directly from the Workflow process in a Synchronise method.

/**

* Given a previous workflow process will add any of the assigned roles to the iterated's

* current workflow process. This basically allows roles to be easily carried over from one

* process to newly created version of the object.

*

* @param previousProcess The process from which to read the previous roles from.

* @param process The process onto which to assign the previous process roles.

* @throws WTException

*/

private static WfProcess assignPreviousProcessRolesToProcess(WfProcess previousProcess, WfProcess process) throws WTException {

@SuppressWarnings("unchecked")

List<Role> processRoles = previousProcess.getProcessRoles();

Iterator<Role> roles = processRoles.iterator();

while (roles.hasNext()) {

Role role = roles.next();

Enumeration principals = previousProcess.getPrincipals(role);

while (principals.hasMoreElements()) {

WTPrincipalReference principal = (WTPrincipalReference) principals.nextElement();

Team team = (Team) process.getTeamId().getObject();

team.addPrincipal(role, principal.getPrincipal());

}

}

log(Level.DEBUG, process, "Previous roles set");

return process;

}