Advanced Reference Qualifier for Specific Role

AndresGT1
Giga Expert

Hello,

I'm barely new to Reference Qualifiers and don't know if there's a way to filter the users table and only show the users that have the role "business_partner"

This is what I found when I searched for something:

javascript:"sys_idIN"+getRoledUsers("itil_admin").join(",")

But I really don't know how it works, that qualifier brings me all users that have at least one role from parent role to child roles

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

getRoledUsers is an OOTB script (see Business Rule getRoledUsers)



// Return an array of sys_ids of the users that have at least one role


// optional parameters allow the exclusion (NOT IN) of some roles or


// look for specific roles (IN)


//


// optional: queryCondition - 'IN' or 'NOT IN'


// optional: roleList - a comma separated list of role names


//


function getRoledUsers(queryCondition, roleList) {


  var roleListIds;


  if (queryCondition && roleList) {


          roleListIds = getRoleListIds(roleList);


  }




  var users = {};


  var gr = new GlideRecord('sys_user_has_role');


  if (roleListIds) {


          gr.addQuery('role', queryCondition, roleListIds);


  }


  gr.query();


  while (gr.next()) {


          users[gr.user.toString()] = true;


  }



  var ids = [];


  for (var id in users)


          ids.push(id);


       


  return ids;


}



So, the syntax your are looking for is



javascript:'sys_idIN' + getRoledUsers('IN','itil_admin').join(",");



No need for custom code



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

5 REPLIES 5

Look at line 18:




gr.addQuery('role', queryCondition, roleListIds);



Check out the API reference for addQuery



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022