The CreatorCon Call for Content is officially open! Get started here.

fetch group members in an array

Vineetha Rohra1
Giga Guru

I want to fetch the group members of a particular group in an array and use it further.

I am using below code but it doesn't return the sys IDs of all members, it returns only sys id of one member multiple times.

var users = [];

var gr = new GlideRecord('sys_user_grmember');

gr.addEncodedQuery("group=b8c3923613038b0014145a132244b05a");

gr.query();

gs.print("query success");

while(gr.next())

{

users.push(gr.user);

//users = users + gr.user + ',';

gs.print("yes");

gs.print("users: "+users);

}

gs.print(users.length);

Where am i going wrong ? Any suggestions would be helpful.

1 ACCEPTED SOLUTION

Kannan Nadar
Tera Guru

Hey Vineetha,



update your users.push(gr.user) to users.push(gr.user+'');


View solution in original post

3 REPLIES 3

Vineetha Rohra1
Giga Guru

Following are the logs after executing above script:



*** Script: query success


*** Script: yes


*** Script: users: 2e826bf03710200044e0bfc8bcbe5de0


*** Script: yes


*** Script: users: c6826bf03710200044e0bfc8bcbe5d87,c6826bf03710200044e0bfc8bcbe5d87


*** Script: yes


*** Script: users: ca826bf03710200044e0bfc8bcbe5d89,ca826bf03710200044e0bfc8bcbe5d89,ca826bf03710200044e0bfc8bcbe5d89


*** Script: 3



It just overrides the sys IDs.


Kannan Nadar
Tera Guru

Hey Vineetha,



update your users.push(gr.user) to users.push(gr.user+'');


Thank you so much. It is working correctly now.