Skip to main content
10-Marble
December 6, 2023
Solved

How to add a user to a Problem Report role via code in Workflow

  • December 6, 2023
  • 1 reply
  • 1119 views

Through code inside the Workflow, I am able to get a specific user's object by querying their email address. I need to add that user to the Customer Role of the Problem Report so that they will be included in future tasks and notifications. So far, I haven't found any examples of this.

 

How do I programmatically add a user object to the Customer role of a problem report? Here is the code I has so far which runs in an expression robot:

 

 

 

String requester_query = "mail=me@gmail.com";

wt.org.DirectoryContextProvider dcp = wt.org.OrganizationServicesHelper.manager.newDirectoryContextProvider((String[])null,(String[])null);
java.util.Enumeration users = wt.org.OrganizationServicesHelper.manager.queryPrincipals(wt.org.WTUser.class, requester_query, dcp);

while (users.hasMoreElements()) {
 wt.org.WTPrincipal principal=(wt.org.WTPrincipal)users.nextElement();
 //principal is the user object that I need to assign to the customer role

 //verify the user was found
 displayName = principal.getPrincipalDisplayIdentifier();
 System.out.println ("Principal Display Identifier - " + displayName);
}

//Add to customer role?

 

 

Best answer by ANNA_02

@Ben_A  Refer this article,

https://www.ptc.com/en/support/article/CS197690

https://www.ptc.com/en/support/article/CS138084

 

Role customeRole = Role.toRole("CUSTOM ROLE NAME");
if(customeRole !=null){
wt.team.TeamHelper.service.addRolePrincipalMap(customeRole, principal, team);
}

1 reply

ANNA_0214-AlexandriteAnswer
14-Alexandrite
December 7, 2023

@Ben_A  Refer this article,

https://www.ptc.com/en/support/article/CS197690

https://www.ptc.com/en/support/article/CS138084

 

Role customeRole = Role.toRole("CUSTOM ROLE NAME");
if(customeRole !=null){
wt.team.TeamHelper.service.addRolePrincipalMap(customeRole, principal, team);
}

Ben_A10-MarbleAuthor
10-Marble
December 14, 2023

@ANNA_02Thank you for the example and links. I ended up using team.addPrincipal instead but I could not have found it without your help.

 

 

//In this example I'm adding the Problem Report's creator to the Customer role. If the role does not currently exist in the team, it is added automatically.

wt.change2.WTChangeIssue pbo =(wt.change2.WTChangeIssue)primaryBusinessObject;
//The role indicated in the following line must be the internal name for that role. For Customer, it is all upppercase.
wt.project.Role customerRole = wt.project.Role.toRole("CUSTOMER");
wt.team.Team team = (wt.team.Team)pbo.getTeamId().getObject();
wt.org.WTPrincipal principal = pbo.getCreator().getPrincipal();
team.addPrincipal(customerRole, principal);