Hi everyone ,
I’ve been working with user management in ThingWorx and came across a related use case to this post
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!
Solved! Go to Solution.
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.
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:
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.
