Skip to main content
15-Moonstone
January 19, 2023
Solved

About the role assignment code in Expression

  • January 19, 2023
  • 2 replies
  • 5032 views

 

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.

Best answer by HelesicPetr

@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

2 replies

HelesicPetr
22-Sapphire II
22-Sapphire II
January 19, 2023

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

avillanueva
23-Emerald I
23-Emerald I
January 19, 2023

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?

smcvr15-MoonstoneAuthor
15-Moonstone
January 20, 2023

how can i add to existing team?

 

HelesicPetr
22-Sapphire II
22-Sapphire II
January 20, 2023

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