- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:21 PM
I have a requirement where we have a catalog item variable field in that we need to populate the count of group members present in the group.
Basically its having a 2000 - number of members present in group count to show in that field
Can anyone help me with that requirement
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:52 PM
I already shared the approach simply subtract
javascript: var count = 0;
var ga = new GlideAggregate('sys_user_grmember');
ga.addQuery('group', 'groupSysId');
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
count = parseInt(ga.getAggregate('COUNT'));
}
count = 2000-count;
count;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:33 PM
so user will select group in 1 variable and then other variable is string where you want to store count
You can use onChange catalog client script with GlideAjax
Use GlideAggregate like this and return the count
I hope you know how to use GlideAjax
var GetGroupMemberCount = Class.create();
GetGroupMemberCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function() {
var groupId = this.getParameter('sysparm_group_id');
var ga = new GlideAggregate('sys_user_grmember');
ga.addQuery('group', groupId);
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
var count = parseInt(ga.getAggregate('COUNT'));
return count.toString();
}
return '0';
}
});
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:37 PM
Hey @Ankur Bawiskar thanks for the reply the group is just one group that will be used there is no variable for group selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:39 PM
then in that string variable use this default value
javascript: var count = 0;
var ga = new GlideAggregate('sys_user_grmember');
ga.addQuery('group', 'groupSysId');
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
count = parseInt(ga.getAggregate('COUNT'));
}
count;
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:43 PM
Hello @Priyanka Chaud1
Just to confirm, you're adding the assignment group name to a text/string field, and that group contains 2,000 members, is that correct?
Thanks