How to Glide users which are not belong to any group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 02:31 AM
Hi,
I have a requirement as follow below.
There are some users in sys_user table which do not have any group and role.
Now how i can glide those users by scripting.
Please provide ur inputs.
Best Regards,
Shaik Nabi khaja.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 03:11 AM
Hi @Shaik nabi khaj ,
You can use either of the scripts mentioned here :
https://www.servicenow.com/community/developer-forum/user-not-a-member-of-group-list/m-p/1465816
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 03:21 AM
Hey Shaik Nabi,
Use the following script to achieve your requirement:
Here I am using three tables:
1. sys_user : Table for all users
2. sys_user_grmember : Table for users and there groups. Only users with group are there in this table.
3 sys_user_has_role: Table for users and there roles. Only users with roles are there in this table.
var userMember=[];
var userwithnorolegroup=[];
var urole=0;
var count=0;
var members=0;
var norolegroup=0;
var userslist= new GlideRecord('sys_user');
userslist.query();
while(userslist.next())
{
var grpMember = new GlideRecord('sys_user_grmember');
grpMember.addQuery('user.sys_id',userslist.sys_id);
grpMember.query();
if(grpMember.next())
{
members++;
}
else
{
count++;
userMember.push(userslist.sys_id.toString());
var userrole= new GlideRecord('sys_user_has_role');
userrole.addQuery("user.sys_id", userslist.sys_id);
userrole.query()
if(userrole.next())
{
urole++;
}
else
{
norolegroup++;
userwithnorolegroup.push(userslist.sys_id.toString());
}
}
}
gs.info(" sys_id of users with no group:")
gs.info(userMember);
gs.info("count of user who doesn't belong to any group: "+ count);
gs.info("count of user who belong to any group: "+ members);
gs.info("count of user who belong to no group but have a role: "+ urole);
gs.info("count of user who belong to no group and who do not even have a role: "+ norolegroup);
gs.info("sys_id of users with no group or role:");
gs.info(userwithnorolegroup);
I hope this helps you, if you find this helpful. Please mark this as helpful and correct. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 07:32 PM
what did you start and where are you stuck?
If you start from your side it will be learning for you as well.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader