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

ThingWorx Navigate is now Windchill Navigate Learn More

Translate the entire conversation x

How to Get All Users from a Specific User Group in ThingWorx?

MA8731174
16-Pearl

How to Get All Users from a Specific User Group in ThingWorx?

Hi everyone ,

   I’ve been working with user management in ThingWorx and came across a related use case to this post 

 

https://community.ptc.com/t5/ThingWorx-Developers/How-to-Find-all-User-Groups-for-a-Given-User/m-p/1038382#M70705

 

about getting all user groups for a given user (using Users[principal].GetGroups()).

 

Now I want to do the reverse:

Get all users that belong to a specific User Group? is it possible? 

 

Thanks in advance for your insights!

ACCEPTED SOLUTION

Accepted Solutions

you can get the direct members of a usergroup like

let result = Groups["Administrators"].GetGroupMembers();

result e.g.

- "Administrator" - type User

- "SomeOtherGroup" - type Group

This will also include contained groups (indicated in the result in the "type" column - group or user). To get also indirect members you would need to iterate over the contained groups and get all members, and repeat. But watch out as TWX groups can create a loop which you must detect and stop iterating a 2nd time.

View solution in original post

5 REPLIES 5

you can get the direct members of a usergroup like

let result = Groups["Administrators"].GetGroupMembers();

result e.g.

- "Administrator" - type User

- "SomeOtherGroup" - type Group

This will also include contained groups (indicated in the result in the "type" column - group or user). To get also indirect members you would need to iterate over the contained groups and get all members, and repeat. But watch out as TWX groups can create a loop which you must detect and stop iterating a 2nd time.

Thank you! do you also have any clue that if there exists also a function with which we can remove all the users which one group has in it? 

I am not aware of such a service. Only deleting members one by one via the DeleteMember service

would you please share a link or how can i see all these services in thingworx? or any resource if you have ?

sure: In script editor either with autocomplete or with the "Me/Entities" feature:

nmutter_0-1760629740929.png

Or via via REST API e.g. <yourhost>/Thingworx/Groups/Administrators/ServiceDefinitions

For Things its easier as you can see the services in Composer directly.

Announcements


Top Tags