Script Include for reference qualifier, for showing groups with atleast one member
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 04:28 AM
Hello Community
The requirement is that I need to create Reference Type Variable and this variable should display Groups from the sys_user_group Table.
But it has 3 conditions :
1. It should ONLY display Active Groups
2. It should ONLY display Groups of XYZ Company
3. It should ONLY display Group members with ATLEAST one member
I want to create a Script Include. And want to use this Script Include as Advance Qualifier for this Reference Variable.
I created a Script but it is not Working at all.
Hope you guys would be able to point out what is wrong with the following Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 04:48 AM
Did you do any logging yet? That's what I do.
Log to see if I'm in the Script Include AT ALL
Log to see the usr query returned anything
Log to see if the array is being generated correctly...
etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 04:52 AM
should be an easy one to handle
what does this mean? -> 2. It should ONLY display Groups of XYZ Company
are you having domain separated instance?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 04:53 AM
Yes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 04:56 AM
you are declaring function within function
try this. ensure this filter is applied correctly for domain, give correct sysId
Call it like this
javascript: new ActiveGroupsWithMembers().getActiveUsersGroups();
var ActiveGroupsWithMembers = Class.create();
ActiveGroupsWithMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getActiveUsersGroups: function() {
var groupIds = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group.active=true');
gr.addEncodedQuery('sys_domain=sysID__of__XYZ__Company');
gr.query();
while (gr.next()) {
if (!groupIds.includes(gr.group.sys_id.toString())) {
groupIds.push(gr.group.sys_id.toString());
}
}
return 'sys_idIN' + groupIds.join(',');
},
type: 'ActiveGroupsWithMembers'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader