List of users within Ignition

Is there a way to get a list of users for a particular role? or even (better) a list of users and their associated roles?

I want to be able to select from a list of users based on where the computer is located. I’ll use the IP (or computer name) and associate the role to that location.

Thank you in advance for any help you can give :wink:

{have your best day ever … today}

You can use system.user.getUsers() to grab all the users in a certain User Source, and then look through the users to create a list of users with a certain role. You can read about this function here:

Correct me if I’m wrong, but this looks like what you want to do:

[code]#Get the all the users with a certain role

#The role
roleToSearch = “Administrator”

#new list with the role we’re looking for
usersList = []

#Get the users in the user source
users = system.user.getUsers("")

#iterate through the users
for user in users:
roles = user.getRoles()
#Check through each role the current user has
for role in roles:
#If they have this role…
if role == roleToSearch:
#…add the user to the usersList above

#print the list of users with the role
print usersList[/code]

The above will print the user objects (username, first name, roles, etc), so you can add some additional code to pull out just the usernames. Add something like this to the end of the above code:

for user in usersList: print user.get(user.Username)

I’m sure there is an easier way to do what you want, but this should get you started.

1 Like