- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 03:54 PM
How to the user id and group name of all the user name and group name listed in sys_user_grmember table using background script inside a variable or just print those details .
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:07 PM
Please use below background script to print user name and group name from sys_user_grmember table.
var sgp = new GlideRecord("sys_user_grmember");
sgp.addQuery('sys_id',"4c744323d711110050f5edcb9e6103e4"); // Please modify your query according to your requirements.
sgp.query();
while(sgp.next()){
gs.print("User id is " +sgp.getDisplayValue('user'));
gs.print("Group name is " + sgp.getDisplayValue('group'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:04 PM
Hi Shiva,
Not sure why you want to add values in variable and then print when you can directly print in while loop.
var gr = new GlideRecord("sys_user_grmember");
gr.query();
while(gr.next()){
gs.print("User name : " + gr.getValue(user.name) + " Group name : " + gr.getValue(group.name));
}
Or you can put these values in array and iterate over it.
Thanks.
PS: Hit like, Helpful, Correct and Endorse, if it answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:06 PM
Hello Shiva,
Below is the script to fetch USER ID and GROUP NAME
var gr = new GlideRecord('sys_user_grmember');
gr.query();
while(gr.next())
{
gs.addInfoMessage("UserId is: " + gr.getValue(user.user_id) + "Group Name is: " + gr.getValue(group.name));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:07 PM
Please use below background script to print user name and group name from sys_user_grmember table.
var sgp = new GlideRecord("sys_user_grmember");
sgp.addQuery('sys_id',"4c744323d711110050f5edcb9e6103e4"); // Please modify your query according to your requirements.
sgp.query();
while(sgp.next()){
gs.print("User id is " +sgp.getDisplayValue('user'));
gs.print("Group name is " + sgp.getDisplayValue('group'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:17 PM
thanks for your help