
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 08:14 PM
Hi ,
Looking for suggestions to improve this script.
I have a requirement to know if a group has only one member in it and that member is a Requested by user.
For this, I created the below script include which is taking userID & GroupID as inputs and checks if the given user is the only available member of the group.
Any suggestions to achieve this without using a GlideRecord inside GlideAggregate...
isUser_the_OnlyMember: function(userID,groupID)
{
var grCheckMemCount = new GlideAggregate('sys_user_grmember');
grCheckMemCount.addQuery('group', groupID);
grCheckMemCount.addQuery('user.active',true);
grCheckMemCount.addAggregate('COUNT');
grCheckMemCount.query();
if(grCheckMemCount.next())
{
if(grCheckMemCount.getAggregate('COUNT') == 1)
{
gs.print("Group has only one member");
//Creating a GlideRecord since Im not able access any value of grCheckMemCount after the getAggregate.
var grUserIsOnlyMem = new GlideRecord('sys_user_grmember');
grUserIsOnlyMem.addQuery('group',groupID);
grUserIsOnlyMem.query();
if(grUserIsOnlyMem.next())
{
if(grUserIsOnlyMem.user == userID)
return true;
else
{return false;}
}
}
else{
return false;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 09:33 PM
Hi,
got it
then the only way is what you mentioned OR the other approach I mentioned
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
‎06-06-2022 09:33 PM
Hi,
got it
then the only way is what you mentioned OR the other approach I mentioned
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
‎06-20-2022 09:39 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader