Skip to main content
1-Visitor
November 15, 2016
Solved

Need to know how to get the users of multiple role from a Library context and add them as a project manager in the project context

  • November 15, 2016
  • 1 reply
  • 2366 views

Im using windchill 10.1 M030, We have written a code for creating project automatically based on the lifecycle state of the document. When the document is released, the project will be created by the listener. Now the users are added manually in the respective roles in the project. Instead i wanted to add a particular members of a role from library as a project manager in the project context. Need help with this.

Best answer by ljeyachandran

Hi all,

I have found the solution. below is the code snippet for achieving this

ContainerTeam libteam = ContainerTeamHelper.service.getContainerTeam((ContainerTeamManaged) pif.getContainer()); (pif is the WTDoc object)

  HashMap map = libteam.getAllMembers();

      Set keys = map.keySet();

      Iterator itr = keys.iterator();

      WTPrincipalReference UserName;

    Object Role1;

    Role ppeRole=null;

      while(itr.hasNext())

    {

      UserName = (WTPrincipalReference)itr.next();

      Role1 = map.get(UserName);

          if(Role1.toString().contains("PDE PLANNING ENGINEER")) (custom role where the users are retrieved)

      {

  System.out.println(UserName.getName() + "-----------------" +Role1);

  ContainerTeamHelper.service.addMember(localContainerTeam, ppeRole.toRole("PROJECT MANAGER"),UserName.getPrincipal() ); (retreived users are added in the role of Project Manager)

        

      }

1 reply

ljeyachandran1-VisitorAuthorAnswer
1-Visitor
December 23, 2016

Hi all,

I have found the solution. below is the code snippet for achieving this

ContainerTeam libteam = ContainerTeamHelper.service.getContainerTeam((ContainerTeamManaged) pif.getContainer()); (pif is the WTDoc object)

  HashMap map = libteam.getAllMembers();

      Set keys = map.keySet();

      Iterator itr = keys.iterator();

      WTPrincipalReference UserName;

    Object Role1;

    Role ppeRole=null;

      while(itr.hasNext())

    {

      UserName = (WTPrincipalReference)itr.next();

      Role1 = map.get(UserName);

          if(Role1.toString().contains("PDE PLANNING ENGINEER")) (custom role where the users are retrieved)

      {

  System.out.println(UserName.getName() + "-----------------" +Role1);

  ContainerTeamHelper.service.addMember(localContainerTeam, ppeRole.toRole("PROJECT MANAGER"),UserName.getPrincipal() ); (retreived users are added in the role of Project Manager)

        

      }

5-Regular Member
July 22, 2020
helped a lot ,thank u very much