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

Add a user to a workflow's PBO's team

Add a user to a workflow's PBO's team

I have a workflow that I'd like to have the user select a user, then have the workflow update the PBO's team and add it to a specific role.


- I created the WTUser variable in the workflow,


- I created a method to take the user and put it into the PBO's team. There is some debugging statements in here and it outputs the team before and the team after.


The expression runs successfully but the before and after team look identical with the user not showing in the output, but if you go to the UI it shows the users.


Any ideas what I'm doing wrong?





public static void addUserToRole(ObjectReference self, String toRole, WTUser currentUser) throws WTException{


Role to_role = Role.toRole(toRole);


wt.team.WTRoleHolder2 team = null;


try {


team = TeamHelper.service.getTeam( (TeamManaged)self.getObject());



System.out.println("_____________BEFORE___________________");


System.out.println("ROLE: " + to_role.toString());


System.out.println("USER: " + currentUser.getFullName());


System.out.println("TEAM: " +team.getDisplayIdentity());



debugTeam(team, currentUser);


TeamHelper.service.addRolePrincipalMap(to_role, (WTPrincipal)currentUser, team );


} catch (TeamException e1) {


e1.printStackTrace();


} catch (WTRuntimeException e1) {


e1.printStackTrace();


} catch (WTException e1) {


e1.printStackTrace();


}


System.out.println("_____________AFTER___________________");


team = TeamHelper.service.getTeam( (TeamManaged)self.getObject());


debugTeam(team, currentUser);


}



private static void debugTeam(WTRoleHolder2 team, WTUser currentUser) throws WTException {


//wt.team.WTRoleHolder2 team = wt.team.TeamHelper.service.getTeam((wt.team.TeamManaged) primaryBusinessObject);


java.util.Vector roles = team.getRoles();


System.out.println("_____________________________________");


System.out.println("ADDING: " + currentUser.getFullName());


for( java.util.Enumeration e = roles.elements(); e.hasMoreElements(); ){


wt.project.Role role = (wt.project.Role) e.nextElement();


java.util.Enumeration participants = team.getPrincipalTarget( role );


System.out.println("ROLE: " + role.toString());



while( participants.hasMoreElements() ){


wt.org.WTPrincipalReference participant = (wt.org.WTPrincipalReference) participants.nextElement();


System.out.println("---Role: " + role.toString() + " Participant: " + participant.getFullName());


}


}


System.out.println("_____________________________________");


}



3 REPLIES 3

RE: Add a user to a workflow's PBO's team

Hi Stephen,


Use this code in Workflow. "self" is a "primaryBusinessObject" OR Modify to suit your requirement,

if(primaryBusinessObject != null){
try{
wt.workflow.engine.WfProcess wfp = ((wt.workflow.engine.WfProcess)(self.getObject()));
wt.team.Team myTeam = wt.team.TeamHelper.service.getTeam(wfp);
if(myTeam == null){
System.out.println("Team does not exist");
throw new wt.util.WTException("Team Does Not Exist");
}
Role to_role = Role.toRole("YOUR ROLE");
wt.team.TeamHelper.service.addRolePrincipalMap(to_role,(wt.org.WTPrincipal)YOURWTUser , (wt.team.WTRoleHolder2)myTeam);
}
catch(Exception e){
System.out.println("Error in workflow expression");
e.printStackTrace();
}
}else{
System.out.println("PBO is null");
}
}

Hope this will help You !!!
Regards
MKR

Re: Add a user to a workflow's PBO's team

I also got it done (if I understood the requirement) with:

((ContainerTeam)contTeam).addPrincipal(role, user);

Re: Add a user to a workflow's PBO's team

Steve - I think your team definition is a little off - try something like this

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