# User Object addRoles vs setRoles

**URL:** <https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625>\
**Category:** Ignition\
**Created:** [March 23, 2026, 5:32pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625 "2026-03-23T17:32:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [March 23, 2026, 5:32pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/1 "2026-03-23T17:32:04Z")

</div>

I encountered this code:

```python
roles=['operator']
userObject.setRoles(roles)

```

But I already know this code:

```python
userObject.addRoles(roles)

```

Similarly `addContactInfo()` vs `setContactInfo()` ?

I am confuse.  
When do I use `set` vs `add`?  
What is the difference?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 23, 2026, 5:51pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/2 "2026-03-23T17:51:04Z")

</div>

I believe the difference is `addRoles()` _appends_ to the current roles list, and `setRoles()` _overrides_ the current list with the one provided to the method.

[System user functions - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/system-user-functions/94045/29)

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [March 23, 2026, 5:58pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/3 "2026-03-23T17:58:17Z")

</div>

That really make sense.

if user have existing roles, `addRoles()` will append to it, while `setRoles()` will overwrite it..  
Same with addContactInfo and setContactInfo.

New User with no existing role, `addRoles()` and `setRoles()` will do the same thing.?!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 23, 2026, 6:02pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/4 "2026-03-23T18:02:15Z")

</div>

> [@Eugene49](#):
>
> New User with no existing role, `addRoles()` and `setRoles()` will do the same thing.?!

Yes.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [March 23, 2026, 6:15pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/5 "2026-03-23T18:15:29Z")

</div>

Thanks a lot.

Forgive me for being slow today. add vs set 😝

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [March 23, 2026, 6:28pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/6 "2026-03-23T18:28:24Z")

</div>

One more thing.

Quoted from ignition manual:

```python
user.set("firstname", "Naomi")
user.set(user.LastName, "Nagata")
user.set("password", "1234567890")

```

is this also valid (i saw this code on existing)?  
`user.set('lastname', "Nagata")`

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 23, 2026, 6:40pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/7 "2026-03-23T18:40:27Z")

</div>

Yes, they will work equivalently, because of some work we're doing under the hood. In theory, the `user.LastName` reference is more "stable" and safer from modifications we might have to do. In practice it's unlikely we'll ever break compatibility in a way that matters to you.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [March 23, 2026, 6:54pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/8 "2026-03-23T18:54:30Z")

</div>

Thanks.

Can you create your own property as well (I saw this on existing code)??  
like  
`userObject.set('home', home_list)`

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/b/0bbce710aff6eafb1575230decea743302279640.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 23, 2026, 8:04pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/9 "2026-03-23T20:04:32Z")

</div>

Yes, you can, but I probably wouldn't recommend it. I don't know if all the serialization machinery is going to respect arbitrary properties you add - they have to both be stored (and reconstituted) when going to the DB/user source/etc, _and_ they have to be serialized/deserialized over RPC.

You can give it a try and see if it works; if it does then it should be fine as long as you stick to something simple like strings on both sides.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 23, 2026, 8:38pm UTC](https://forum.inductiveautomation.com/t/user-object-addroles-vs-setroles/114625/10 "2026-03-23T20:38:36Z")

</div>

I've done this by using notes to store a JSON string that can be parsed to get "custom properties." There may be a better way though 🤷‍♂️
