I am trying to get all members of group, instead getting only one member

Gayathri5
Tera Guru

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

1 ACCEPTED SOLUTION

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.

View solution in original post

12 REPLIES 12

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.

Hi Tran, 

 

ya i also tried the same way and it worked..anyway thanks

Thank you. Could you accept my solution for this issue.