- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2022 04:02 AM
Hi All,
var gm = new GlideRecord('sys_group_has_role');
gm.addQuery('group.name','IN',groups);
gm.addEncodedQuery('role.nameLIKEitil');
gm.query();
while(gm.next())
{
test.push(gm.group.name);
}
var au = new ArrayUtil();
var uniqueArrayElements = au.unique(test);
gs.info(uniqueArrayElements);
from this code i want to get the number of groups from the array "uniqueArrayElements" how can we get this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2022 04:04 AM
Hi
var gm = new GlideRecord('sys_group_has_role');
gm.addQuery('group.name','IN',groups);
gm.addEncodedQuery('role.nameLIKEitil');
gm.query();
gs.info("Group Count"+ gm.getRowCount())
while(gm.next())
{
test.push(gm.group.name);
}
var au = new ArrayUtil();
var uniqueArrayElements = au.unique(test);
gs.info(uniqueArrayElements);
gs.info(uniqueArrayElements.length);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2022 04:04 AM
Hi
var gm = new GlideRecord('sys_group_has_role');
gm.addQuery('group.name','IN',groups);
gm.addEncodedQuery('role.nameLIKEitil');
gm.query();
gs.info("Group Count"+ gm.getRowCount())
while(gm.next())
{
test.push(gm.group.name);
}
var au = new ArrayUtil();
var uniqueArrayElements = au.unique(test);
gs.info(uniqueArrayElements);
gs.info(uniqueArrayElements.length);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2022 04:07 AM
Add
gs.info(uniqueArrayElements.length);
to the last line for a check
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2022 04:18 AM
Hi,
you already have array and print the length as mentioned by Jaspal
Regards
Ankur
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-04-2022 04:51 AM
Hi,
In that way it is returning the total number of characters of the group name