Filtering Users based on the Group Membership in the list view

Mike50
Kilo Guru

Hello Community,

 

I am trying to find out what are the options to achieve the following goal:

In the specific list (table) that contains column with User references, I want to be able to filter out records based on the Group Membership.

Example 1: In the Incident list, I want to be able to filter out all records where Caller is a member of the specific Group.

Example 2: In the Change Request list, I want to to be able to find all Changes Requested by members of the specific Group.

 

I am not looking for a generic solution that would work in all lists. It is fine if solution works for the specific Table.

 

Please, let me know if you have any suggestions.

 

Thank you in advance!

4 REPLIES 4

anshul_goyal
Kilo Sage

Hi @Mike50,

Example 1: In the Incident list, I want to be able to filter out all records where Caller is a member of the specific Group.
Please use the below script: 

Type: Business Rule
Table: Incident
When to run: Before 
Operation: Query

Script: 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
if (gs.getUser().isMemberOf("specific_group")) {
current.addQuery("caller_id", gs.getUserID());
}
 
})(current, previous);

Example 2: In the Change Request list, I want to to be able to find all Changes Requested by members of the specific Group.

Please use the below script: 

Type: Business Rule
Table: Change Request
When to run: Before 
Operation: Query

Script: 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
if (gs.getUser().isMemberOf("specific_group")) {
current.addQuery("requested_by", gs.getUserID());
}
 
})(current, previous);

I hope this will solve your problem. Please mark it as Accepted and Helpful.

GoodWill,
Anshul

Ankur Bawiskar
Tera Patron
Tera Patron

@Mike50 

it depends on which field you want to apply filter and based on what condition.

Each table can and should have it's own filter condition.

what's your challenge for caller field on inciddent

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

AnveshKumar M
Tera Sage
Tera Sage

Hi @Mike50 

It is not possible to have a filter in list views as described in the requirement. The possible option is using dynamic filter, if you have groups in single digit number you can create a dynamic filter for each group. You can refer the following docs.

 

https://docs.servicenow.com/en-US/bundle/vancouver-platform-user-interface/page/use/using-lists/task...

 

Thanks,
Anvesh

Taha Habib
Tera Guru

Hello Mike,

I believe we cannot get to the group of the caller field as it is a related field to the caller field, so it might not be possible to filter out the records on incident table where caller is member of a specific group via filters in list view.

However, you can always use script to achieve the same.

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("group", "287ebd7da9fe198100f92cc8d1d2154e"); //the group you choose
gr.query();
while(gr.next())
{
   var inc = new GlideRecord('incident');
   inc.addQuery("caller_id", gr.user);
   inc.query();
   while(inc.next())
   {
      gs.info(inc.number + ", " + inc.short_description);
     
   }
       
}

 

I hope this answer helps you. Please mark it as correct and helpful, if it helps you. Thank you.