# System user functions

**URL:** <https://forum.inductiveautomation.com/t/system-user-functions/94045>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 1, 2024, 2:41pm UTC](https://forum.inductiveautomation.com/t/system-user-functions/94045 "2024-08-01T14:41:52Z")\
**Posts on this page:** 1\
**Showing post:** 29

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [August 8, 2024, 1:58pm UTC](https://forum.inductiveautomation.com/t/system-user-functions/94045/29 "2024-08-08T13:58:55Z")

</div>

It works now!

It seem .setRoles does not work.  
.addRole does.

I had tried importing java string, and then making my string for the role into a java string. Well it sort of worked, but then I got an error that some kind of python object could not be converted.

So then I went with addRole.

Thanks so much for all the help.

```python
# List of emails to check against
email_list = ["email1@example.com", "email2@example.com", "email3@example.com"]

# Retrieve all users
users = system.user.getUsers('default')

# Loop through each user
for user in users:
    # Get contact info for the user
    contacts = user.getContactInfo()
    
    # Check if any contact is an email in the email_list
    for contact in contacts:
        if contact.contactType == "email" and contact.value in email_list:
            # Get the user's current roles
            current_roles = user.getRoles()
            
            
            # Append the role if not already present
            if "roleThatExists" not in current_roles:
                print user                
                user.addRole("roleThatExists")
               
                response =system.user.editUser("default", user)
                print response.getErrors()

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/system-user-functions/94045)._
