- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 10:23 AM
Hi experts,
I am using below code to get all users of some group, instead only 1 user is coming...where i am going wrong
var ans =[];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group=d625dccec0a8016700a222a0f7900d06');//sysid of some group
gr.query();
if(gr.next()){ // tried with while, but it is coming like Hello A, Hello A, B Hello A,B,C ...which i dont in this fashion
//ans.push(gr.user.name); //tried this as well...only 1user coming
ans.push(gr.getValue('user'));
gs.print("Hello"+ans);
}
I want Hello A, B,C, D..etc like this all users in the same array, can anyone tell me what mistake i am doing, how to resolve this?
Regards,
g
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 08:39 PM - edited 11-29-2022 08:39 PM
Ok I got it. you want to output: Hello A,B,C, ... right?
var ans =[];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group=d625dccec0a8016700a222a0f7900d06');//sysid of some group
gr.query();
while(gr.next()){ // tried with while, but it is coming like Hello A, Hello A, B Hello A,B,C ...which i dont in this fashion
//ans.push(gr.user.name); //tried this as well...only 1user coming
ans.push(gr.getDisplayValue('user'));
}
var str = ans.toString();
gs.print("Hello"+" "+ str);
Could you try again?
I believe that it can work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 10:35 AM
Okay I thought you want display names. Use below to get the sys Id of all the users . If you are running this on workflow for approval activity then uncomment answer=ans;
var ans =[];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group=d625dccec0a8016700a222a0f7900d06');//sysid of some group
gr.query();
while(gr.next()){
ans.push(gr.getValue('user'));
gs.print("Hello"+ans);
}
//answer = ans;
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 10:39 AM
I am not using workflows instead approval rules in Vulnerability response module, i just wanna send approvals to all users, i had put in array but its still its sending to one person.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 10:37 AM
Hi Gayathri,
Try this
var ans =[];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group=d625dccec0a8016700a222a0f7900d06');//sysid of some group
gr.query();
while(gr.next()){ // tried with while, but it is coming like Hello A, Hello A, B Hello A,B,C ...which i dont in this fashion
//ans.push(gr.user.name); //tried this as well...only 1user coming
ans.push(gr.getDisplayValue('user'));
}
gs.print("Hello"+' '+ans);
Mark Correct and Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 06:21 PM
Hello Gayathri5.
You should use "while" to loop all record in group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:10 PM
Hi,
No Approvals are not sending to all members in the array..to only 1 person its sending.