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

We are happy to announce the new Windchill Customization board! Learn more.

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

arajendren
8-Gravel

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Prabhash
5-Regular Member
(To:arajendren)

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.

View solution in original post

9 REPLIES 9
Prabhash
5-Regular Member
(To:arajendren)

Hello Anuradha,

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

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.

Prabhash
5-Regular Member
(To:arajendren)


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.

Hi, the challange with this will be, that you can filter all the necessary groups. The result will include all the different role groups. Probably you need to get the repository or the base dn to get the groups you are looking for.

Björn

WTPrincipal prince = SessionHelper.manager.getPrincipal();

logger.debug("prince = " + prince);

Enumeration e = OrganizationServicesHelper.manager.parentGroups(prince, false);

while (e.hasMoreElements()) {

WTPrincipalReference o = (WTPrincipalReference)e.nextElement();

WTPrincipal localPrince = o.getPrincipal();

logger.debug("localPrince = " + localPrince.getClass().getName());

if (localPrince instanceof WTGroup) {

WTGroup group = (WTGroup) localPrince;

logger.debug("Group = " + group.getName());

}

}

Hi,

Thanks a lot for the answer.But with this code as well I am getting only following results:

MEMBERS

PTC A

PTC,and some more answers.

(i.e Results shows even the organization name,Role Name in team,etc)

I need to get only PTC A.

Thanks,

Anuradha

Hi,

Thanks a lot for the answer.But with this code as well I am getting only following results:

MEMBERS

PTC A

PTC,and some more answers.

(i.e Results shows even the organization name,Role Name in team,etc)

I need to get only PTC A.

Thanks,

Anuradha

Prabhash
5-Regular Member
(To:arajendren)

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.

LoriSood
22-Sapphire II
(To:arajendren)

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.

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

Top Tags