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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

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

Ben_A
8-Gravel

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

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ANNA_02
13-Aquamarine
(To:Ben_A)

@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);
}

View solution in original post

2 REPLIES 2
ANNA_02
13-Aquamarine
(To:Ben_A)

@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_A
8-Gravel
(To:ANNA_02)

@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);

 

Top Tags