- 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:28 AM - edited 11-29-2022 10:28 AM
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.getDisplayValue('user'));
gs.print("Hello"+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:31 AM
I wanna send approvals to all the users of the group, which is not happening with above my code and your code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 10:34 AM - edited 11-29-2022 10:34 AM
If you are using a workflow, you can just add the group here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 10:38 AM
Hi Mike,
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.