2 Steps to Create a Dynamic Filter that Returns Groups Logged in Users Belong to
Dynamic filter options enhance filtering by allowing users to run existing script includes or JavaScript against a reference field within condition builders and dynamic reference qualifiers.
There is a delivered dynamic filter 'One of My Group's which uses the getMyGroups() API. However, this also returns the parent groups of the groups where the current user (logged in) belongs to.
Read User is able to see a list of records from the groups that user is a part of and also the groups whi... for more information
The example below can help if you want to filter based on groups where the user (logged in) belongs. This would query the sys_user_grmember table and returns the list of groups for the User (based on the UserID).
Get started by understanding how to create a dynamic filter option.
This custom business rule will query the sys_user_grmember table and return the list of groups where the user belongs to. Ensure 'Client callable' is enabled . You would need to configure the form layout to make the 'Client callable' flag/field visible*.*
Get start with your business rule here: Create a business rule.
Script:
function getGroup() {
var groups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',gs.userID());
gr.query();
while (gr.next())
{
groups.push(gr.group.toString());
}
return groups;
}
It should look like this:
Step 2. Create a custom dynamic filter
- Navigate to System Definition > Dynamic Filter Options
- Use the information to populate the record:
Label = My Group Script : getGroup() Field Type= Reference Referenced Table= Group (sys_user_group) Order = 200 Reference script: Business Rule: FilterOnGroup
Available for filter : True (enabled)
https://www.servicenow.com/community/in-other-news/2-steps-to-create-a-dynamic-filter-that-returns-groups-logged-in/ba-p/2293910