Dynamic filter one of my group members
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi,
Im trying to create a dynamic filter that will return all users from my groups but i had no luch. What am I doing wrong?
var OneOfMyGroupMembers = Class.create();
OneOfMyGroupMembers.prototype = {
initialize: function() {},
getMyGroupMembers: function() {
var groups = gs.getUser().getMyGroups();
var groupQuery = groups && groups.join ? groups.join(',') : String(groups || '');
if (!groupQuery)
return '';
var users = [];
var seen = {};
var member = new GlideRecord('sys_user_grmember');
member.addQuery('group', 'IN', groupQuery);
member.addQuery('user.active', true);
member.query();
while (member.next()) {
var userId = member.getValue('user');
if (userId && !seen[userId]) {
seen[userId] = true;
users.push(userId);
}
}
return users.join(',');
},
type: 'OneOfMyGroupMembers'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
the script include should be client callable
your script include has initialize() method so it will break
check this
Create your own Dynamic Filters - ServiceNow Community
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
@Ankur Bawiskar can you pls help me to adjust it to be client callable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
just follow the article which I shared.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @Alon Grod
You can try with following script. It will return the sys_id of the group members where logged in user is assigned.
Also you can refer this article : 2 Steps to Create a Dynamic Filter that Returns Groups Logged in Users Belong to
var OneOfMyGroupMembers = Class.create();
OneOfMyGroupMembers.prototype = {
initialize: function() {
},
getMyGroupMembers: function() {
var userGroupIds = [];
var UserIds = [];
// 1. Get all groups where the logged-in user is a member
var loggedInUser = gs.getUserID();
var userGroupGR = new GlideRecord('sys_user_grmember');
userGroupGR.addQuery('user', loggedInUser);
userGroupGR.query();
while (userGroupGR.next()) {
userGroupIds.push(userGroupGR.getValue('group'));
}
// If the user belongs to no groups, return an empty filter or handle accordingly
if (userGroupIds.length === 0) {
return loggedInUser;
// 2. Get all users who are members of those specific groups
var peerGR = new GlideRecord('sys_user_grmember');
peerGR.addQuery('group', 'IN', userGroupIds.join(','));
peerGR.query();
while (peerGR.next()) {
var memberId = peerGR.getValue('user');
if (UserIds.indexOf(memberId) === -1) {
UserIds.push(memberId);
}
}
return UserIds;
},
type: 'OneOfMyGroupMembers'
};
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
