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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Programmatically assign a task participant

jasonb1
1-Newbie

Programmatically assign a task participant

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 7
rmk
1-Newbie
1-Newbie
(To:jasonb1)

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

jasonb1
1-Newbie
(To:rmk)

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

MatthewKnight
4-Participant
(To:jasonb1)

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.

Matthew,

Thanks for the repsonse. I haven't worked on this in a few days. I am wondering, populate the roleon the PBO team.

Where would I get the value to poplulate the role with? In my case, I have three roles on the context team that have defined users, for a given review task depending on the type of document, it would be one of those three.

Maybe I'm overlooking something that makes this easier to do.

Thanks,

Jason

MatthewKnight
4-Participant
(To:jasonb1)

Not sure. Maybe I don't fully understand the problem. You want to conditionally assign an activity to participants from either RoleA, RoleB, or RoleC? Create RoleD and copy the principals to that role. The container team's roles/principals are probably on the pbo team, so you should just be able to use wt.team.TeamHelper. If not, you'll have to use wt.inf.team.ContainerTeamHelper to find them on RoleA, RoleB, or RoleC, and TeamHelper to create them against RoleD.

ContainerTeamHelper.service.findRolePrincipalMap might work, but I don't think I've used that one.

I would probably use something like:

WTContainer container = ((WTContained)primaryBusinessObject).getContainer();

ContaineTeam containerTeam = ContaineTeamHelper.service.getContainerTeam(((ContainerTeamManaged)container));

Team team = TeamHelper.service.getTeam((TeamManaged)primaryBusinessObject);

WTGroup group = ContainerTeamHelper.service.findContainerTeamGroup(containerTeam, ContainerTeamHelper.ROLE_GROUPS, roleA.toString()); //or roleB or roleC...

Enumeration<?> members = group.members();

while(members.hasMoreElements()) {

WTPrincipal next = (WTPrincipal) members.nextElement();

TeamHelper.service.addRolePrincipalMap(roleD,next,team);

}

No..you're not missing the problem, I just mis-understood where you meant to get the value for RoleD...I see what you that I will still have my other three roles on the team to pull from.

Thanks,

Jason

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;

}

Top Tags