How can i fetch user list having a specific role.

Hemant13
Kilo Contributor

My requirement:

I have created a role, provisioning_approval.

I have created few users and among them i have assigned this role to 3 of them.

I have a form and there i want to list the approval names(select box).

So do we have a way through client script i can directly fetch users having that role assigned to them.

I tried an onLoad script but not sure how to fetch correct list bcz below is giving me current user name.

if(g_user.hasRole('provisioning_approval')) {
    g_form.addOption('app',g_user.getFullName(), g_user.getFullName());
}

 

  1. Do we have any way to fetch User list based on role
  2. Should i go through each user in loop and check their role and add in the drop down list.

 

 

Please help and let me know if any other details are required.

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

If you want all the users with your specific role no need to write script, you can create a lookup select box instead of select box with following conditions:

find_real_file.png

replace the sys_id of your role, in reference qualifier.


Raghav
MVP 2023

View solution in original post

13 REPLIES 13

Hi @Raghav 

I did try this,

  • If I assign "itil" role to any of my newly created user then it works fine but this role comes with many other inherit list.
  • If i assign my created role to any of servicenow existing user then also it works fine.(because that user already has "itil" role.

So could you please let me know if there is any specific role I have to assign my new user to make it work from the "itil" list.

Also can I have that role as part of the role which I have created so I(admin) don't have to assign multiple roles to any such user.(if it auto inherits or something without much manual intervention).

Or if there is any alternative available to "itil" role.

 

What are the significance of assigning a user "itil" role.

 

Also, I didn't find any role naming as "snc_internal"

 

find_real_file.png

The significance of ITIL role here is that it is defined in the ACl:

find_real_file.png

since "snc_internal" role is not present in your instance you can try following:

 

1. Remove all roles from "Read ACL" on sys_user_has_role table and then try.

 


Raghav
MVP 2023

Hi, 

If you only need access to read the data from approvals table, grant the "approver_user" role to the users, and it should be able to fetch you the list from the approvals table.

Thanks & Regards,

Rishabh Jha

Aavenir (http://www.aavenir.com/)

Hemant13
Kilo Contributor

Thanks everyone for your responses.

 

This is what I followed which worked for me:

  • Created a lookup select box as suggested above.
  • Imported itil to the role provisioning_approval that I have created.
  • Assigned the role to the user I have created.
  • User got both the roles and it worked fine.