- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 05:10 AM
Hello,
I've a requirement to check whether the user is part of a group. If it is then I've log it to file or something to do.
Here is my script and I'm not getting desired output, please let me know what is the issue with the script, is it because of dot walk fields. Please help me here.
var gr = new GlideRecord('sys_user');
gr.initialize();
gr.query();
while(gr.next()){
//gs.info(gr.user_name);
var gm = new GlideRecord('sys_user_grmember');
gm.initialize();
gm.addQuery('sys_user_grmember.user.sys_id',gr.sys_id);
gm.Query;
while(gm.next()){
gs.info('In');
if(gm.group.sys_id == 'aead02002f26011048be265df699b6a3'){
gs.info(gr.user_name);
//Do something
}
}
}
Appreciate any suggestions!!
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 07:17 AM
Hi,
then do this
var gr = new GlideRecord('sys_user');
gr.query();
while(gr.next()){
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group.name', 'Capacity');
gm.addQuery('user', gr.getUniqueValue());
gm.query();
if(gm.next()){
gs.info("User " + gr.getDisplayValue() + ' is member of ' + 'Capacity');
}
}
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
‎04-01-2022 05:15 AM
Hi,
which user to check?
something like this
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group.name', 'Capacity');
gm.addQuery('user.user_name', 'abel.tuter');
gm.query();
if(gm.next()){
gs.info("Is member");
}
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
‎04-01-2022 05:30 AM
I would like to check all users from sys_user table. Loop through each and check if user is part of a group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 07:17 AM
Hi,
then do this
var gr = new GlideRecord('sys_user');
gr.query();
while(gr.next()){
var gm = new GlideRecord('sys_user_grmember');
gm.addQuery('group.name', 'Capacity');
gm.addQuery('user', gr.getUniqueValue());
gm.query();
if(gm.next()){
gs.info("User " + gr.getDisplayValue() + ' is member of ' + 'Capacity');
}
}
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
‎04-03-2022 08:35 PM
@Kishore
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader