Skip to main content
9-Granite
March 15, 2015
Solved

How to get the group names of the user who has logged in .Need to achieve this using Windchill API.

  • March 15, 2015
  • 2 replies
  • 6463 views

Need to get the group names that user belongs to. Need to get using Windchill API.

Best answer by Prabhash

Anuradha, do you happen to have a coding background? If yes, then road ahead is fairly simple. You will have to deduce a logic based on your environment, and filter out the the group which you are looking for using few lines of Java code.

Some of the generic logic i could think of:

a) You can manage all the potential group names using a property file and filter out groups at run time by comparing with groups stored in property file.In this way you can always add up new potential groups if needed in to the property and there will be no need to modify the class files.But, drawback with this approach would be, you will have to restart the server every time after property file modification.

b) If you really want things to be totally dynamic, then instaed mainitaining group names in a property file maintain in a custom preference.

But having said that it depends on your data set, what is going to be best for you.

2 replies

1-Visitor
March 16, 2015

Hello Anuradha,

If you could elaborate your problem statememnt a bit, it will be easier to help you out with the solution.

9-Granite
March 16, 2015

Take for example I have an organization PTC and groups created as PTC A,PTC B,PTC C.

The user 1 belongs to PTC A and user 2 belongs to PTC B.

When the user 1 logs in and creates a promotion request,need to get the Group name of User 1 i.e PTC A through API.This API Iam calling in the workflow used by promotion request.Using this group name I need to execute a logic in workflow.

I am unable to get the group name PTC A at present.

Appreciate any inputs.

Thanks.

1-Visitor
March 16, 2015


You can use below snippet to fetch the group of a user:

Enumeration enumeration = OrganizationServicesHelper.manager.parentGroups(SessionHelper.manager.getPrincipal(),false);

while (enumeration.hasMoreElements()) {

String groupName = ((WTPrincipalReference)enumeration.nextElement()).getPrincipal().getName();

}

Let me know if you need more info.

23-Emerald II
April 10, 2015

Anuradha, were you able to get what you needed? it seems like the basics were given here, but some further customization of the code may be required to work in your specific environment.

Please let us know if you have specific further questions or if this thread can be closed out.

9-Granite
April 14, 2015

Hi Lori/Prabash,

I tried the solution same as Prabash suggested.(Creating a property file to store group names.Then compare the results with it to get the correct group name).

Am able to get the correct group names now.

Thanks for the suggestions.

Thanks,

Anuradha