I’m trying to figure out how to populate a dropdown list with the users saved into the ignition gateway but I can’t find a way to do it. The idea is to populate it when the log in page is opened.
I can’t find an example to start from, could you kindly help me please?
I have a function in a shared script so I can use it from any project.
def getEmployees(source, role):
'''
returns a datset of user names based on the user source and role filters
'''
header = ['user']
opList = []
exceptions = ['autologin', 'Test User', 'admin']
users = system.user.getUsers(source)
for user in users:
roles = user.getRoles()
if role in roles:
username = user.get('username')
if username not in exceptions:
opList.append([username])
ds = system.dataset.toDataSet(header,opList)
return ds
This is very useful, now I have to figure out how to use a shared script. Is right to creare the script in “Scripting” → “Project library” or is the wrong path?
what version are you on? for v7.9 you have a global shared script. In v8 you have a global inherited project that stores your global scripts. Otherwise, it is a project script.
for v7.9 its like
shared.<yourScriptNameHere>.<functionName>
IE shared.users.getEmployees(<anyVariablesUsedHere>)
or
project.users.getEmployees()
The first argument is the source of the users as defined in the Gateway User Sources. Every gateway starts out with a “default” source, more may have been added to your gateway.
The second argument filters on users based on a specific role. For example, if “Administrator” is used as the second argument, the function will return users that have the role Administrator.
The proper way to call the function is getEmployees('my_user_source', 'role_of_users')
replacing my_user_source and role_of_users with a real user source and role.
Thanks for the example, now it’s working… I’ve just modified the script in this way:
def getEmployees(source):
'''
returns a datset of user names based on the user source and role filters
'''
header = ['user']
opList = []
users = system.user.getUsers(source)
for user in users:
roles = user.getRoles()
if not 'Administrator' in roles and not 'Operatore' in roles:
username = user.get('username')
opList.append([username])
ds = system.dataset.toDataSet(header,opList)
return ds
In this way I show only roles that aren’t Administrator or Operatore, is correct as I modified or it should be done better?
Another question, I put the follow code to populate a dropdown when on in the visionWindowOpened of my login page
I take this opportunity to ask if you have the same problem I’m having with the Dropdown; now I’m populating the dropdown with your script and everybody can choose their own user, but I need to insert manually another user if is needed (for example Admin), so I change the Selection Mode to Editable, but when I start to write the first letter, the dropdown choose automaticly the first word already present in its data and I’m not free to insert what I want. I red in this link ( Bug on dropdown in editable selection mode ) that the problem has not been solved.