- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 09:07 PM
Hi All,
I want to check if the logged in user is only part of some particular group. for example, i want to check the logged in user is part of only 'itil' group.
Thanks in Advance,
Sachin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 09:39 PM
Okay so you have to do a GlideRecord query of (sys_user_grmember) table and check if the logged in user has only 1 group assigned to them. If count is more than 1 then check if the group is (itil). If the group is (itil) then return true.
Below is the code:
var grGroup = new GlideRecord('sys_user_grmember')
grGroup.addQuery('user',gs.getUserID());
grGroup.query();
var count = grGroup.getCount();
if(count>1)
{
return false; //or whatver you want to do
}
else
{
if(grGroup.getDisplayValue('group') == 'itil')
{
return true; //or whatever you want to do here.
}
}
I have written this code here so some syntax might be incorrect but logic is right. Please let me know if you need more help.
If my answer was helpful please mark it Helpful or Correct.
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 12:13 AM
where you wish to check this? on which form?
use this script and it will tell if logged in user is member of only itil group and no other group
var grGroup = new GlideRecord('sys_user_grmember')
grGroup.addQuery('user',gs.getUserID());
grGroup.addQuery('group.name', 'itilGroup');
grGroup.query();
if(grGroup.getRowCount() == 1){
return 'true'; // it means only 1 group
}
else{
return 'false'; // it means user belongs to some other group or user belong to multiple groups or user is not member of any group
}
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
05-30-2023 12:47 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader