# filterUser() extension function help

**URL:** <https://forum.inductiveautomation.com/t/filteruser-extension-function-help/11411>\
**Category:** Ignition\
**Created:** [March 24, 2016, 3:34pm UTC](https://forum.inductiveautomation.com/t/filteruser-extension-function-help/11411 "2016-03-24T15:34:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrdiggy76](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rrdiggy76/32/3741_2.png) [@rrdiggy76](https://forum.inductiveautomation.com/u/rrdiggy76)\
**Post date:** [March 24, 2016, 3:34pm UTC](https://forum.inductiveautomation.com/t/filteruser-extension-function-help/11411/1 "2016-03-24T15:34:34Z")

</div>

Hi all,

I’m trying to filter some users in the User Management component using the filterUser extension function but can’t get it to work for me. I’m sure i’m doing something wrong, just can’t see what it is!

I want to look at the logged in user and basically hide all roles above them in the hierarchy, so Administrator\>Lead\>Operator where an Admin can sell all users a Lead logged in can only see the same other users with the Lead role and below etc.

I have the following code in the filterUser extension function;

[code]userName = system.security.getUsername() # logged in user  
userIn = system.user.getUser("", userName)  
rolesIn = userIn.roles # roles for current user  
roleNames = user.getRoles() # inspect user role loaded in management table

if “Administrator” in rolesIn:  
print “Admin”  
return 1  
elif “Lead” in rolesIn:  
if roleNames == “Administrator”:  
print “Success!”  
return 0  
else:  
print roleNames #here my console window shows all roles in management table  
return 1  
else:  
return 0[/code]

I have the print roleNames to help me debug - basically the console window will proceed to display the roles of each user in the management table.

I have 5 users and get the following in the console when logged in with a user with the “Lead” role;

[Administrator]  
[Lead]  
[Administrator]  
[Lead]  
[Operator]

For reference, if logged in as Admin, i get [Admin] in the console 5 times as expected

Any ideas???

---

<div class="post-metadata">

**Author:** ![rrdiggy76](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rrdiggy76/32/3741_2.png) [@rrdiggy76](https://forum.inductiveautomation.com/u/rrdiggy76)\
**Post date:** [March 30, 2016, 7:15pm UTC](https://forum.inductiveautomation.com/t/filteruser-extension-function-help/11411/2 "2016-03-30T19:15:13Z")

</div>

Any thoughts anyone?

---

<div class="post-metadata">

**Author:** ![WillMT10](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@WillMT10](https://forum.inductiveautomation.com/u/WillMT10)\
**Post date:** [March 30, 2016, 8:16pm UTC](https://forum.inductiveautomation.com/t/filteruser-extension-function-help/11411/3 "2016-03-30T20:16:56Z")

</div>

I think switching line 10 from: `if roleNames == "Administrator":` to: `if "Administrator" in roleNames:` should do the trick.

-Will

---

<div class="post-metadata">

**Author:** ![rrdiggy76](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rrdiggy76/32/3741_2.png) [@rrdiggy76](https://forum.inductiveautomation.com/u/rrdiggy76)\
**Post date:** [March 30, 2016, 9:56pm UTC](https://forum.inductiveautomation.com/t/filteruser-extension-function-help/11411/4 "2016-03-30T21:56:33Z")

</div>

WillMT10, you are a genius my friend! Thank you, this has been driving me stir crazy.
