Skip to main content
Jan 19, 2023 12:37 PM UTC
Solved

About the role assignment code in Expression

 

wt.org.DirectoryContextProvider contextProvider = wt.inf.container.WTContainerHelper.service.getExchangeContainer().getContextProvider();
 wt.org.WTGroup wgroup = wt.org.OrganizationServicesHelper.manager.getGroup("YONETICI", contextProvider);
	 wt.query.QuerySpec qs = null;
 qs = new wt.query.QuerySpec(wt.org.WTGroup.class);
 wt.query.SearchCondition sc = new wt.query.SearchCondition(wt.org.WTGroup.class, wt.org.WTGroup.NAME, wt.query.SearchCondition.EQUAL, "YONETICI");
 qs.appendWhere(sc, new int[] { 0 });

 for(wt.fc.QueryResult queryResult = wt.fc.PersistenceHelper.manager.find(qs); queryResult != null && queryResult.hasMoreElements();)
 wgroup = (wt.org.WTGroup)queryResult.nextElement();

 java.util.ArrayList<WTUser> members = new java.util.ArrayList<WTUser>();
 java.util.Enumeration<wt.org.WTPrincipal> member = wgroup.members();

 while (member.hasMoreElements()) {
 wt.org.WTPrincipal principal = (wt.org.WTPrincipal) member.nextElement();
 if (principal instanceof WTUser){
 members.add((WTUser) principal);}
 }

 wt.team.Team team = new wt.team.Team();
	 team.setName("My Team");
	 wt.org.WTPrincipal wtprincial = members.get(0);
 wt.project.Role role = wt.project.Role.toRole("Submitter");

 if (role == null) { 
 team.addPrincipal(role, wtprincial); 
 team.addPrincipal(wt.project.Role.toRole("Submitter"), wtprincial); 
 wt.fc.PersistenceHelper.manager.save(team);
 team = (wt.team.Team)PersistenceHelper.manager.refresh(team); 
 }

 

 

The code above does not give an error, but when I run the flow, it does not return a user to me. There is a registered user in the "YONETICI" group, I want to assign that user to the Submitter role and send a task, but the task does not go to the user.

Jan 24, 2023 2:32 PM UTC

@smcvr 

Additional information.

 

if you use a Variable to assign a participant do not use wt.project.Role. It can not work this way, Role as a object do not contains members it is just Enumeration. Use WTParticipant type or WTUser. 

 

Also the variable can not be used as you use it with wt.team.TeamHelper.service.addRolePrincipalMap. 

The assignee is a role from a team connected with primaryBusinessObject not with Variable of the task. 

 

PetrH

15 replies

Jan 19, 2023 1:58 PM UTC

Hi @smcvr 

Show screen shot of workflow that others can imagine where the code and task are run

 

Check BacgroudnMethodServer.log if there is any error from WF

 

Last point the method Role.toRole("NAMEOFROLE") has to use internal name of the ROLE so Submitter I guess is SUBMITTER

 

PetrH

Jan 19, 2023 7:16 PM UTC

Looks like you are creating a new team, not modifying the existing team of the workflow or PBO.  There is no tying the team you created to the workflow. Did I miss something?

smcvrAuthor
Jan 20, 2023 7:22 AM UTC

how can i add to existing team?

 

Jan 20, 2023 7:53 AM UTC

Hi @smcvr 

Get the team from the object where the workflow is running on by following code

 

wt.team.Team team = wt.team.TeamHelper.service.getTeam(ci); // CI is a object Change Issue, WTPart, ChangeRequest, PromotionRequest what ever. 

 

 

@avillanueva good point with the new Team I didn't check the code so carefully 😄

 

PetrH