- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:29 PM
Hello,
I am trying to get users sys_id's from sys_user_grmember table for one particular group(X). (X) group have 13 group members. I have written a code. however It seems code is not working. It prints only one sysid multiple times.
sys_idIN0b41c7dbdbf007000fc9ff7dae9619fd,0b41c7dbdbf007000fc9ff7dae9619fd,0b41c7dbdbf007000fc9ff7dae9619fd,0b41c7dbdbf007000fc9ff7dae9619fd,0b41c7dbdbf007000fc9ff7dae9619fd
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:32 PM - edited 03-05-2024 07:33 PM
Hi @Vinay49 ,
var users = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery("group=b8c3923613038b0014145a132244b05a");//update sys_id
gr.query();
gs.print("query success");
while(gr.next())
{
users.push(gr.user+'');//your code change to this line
}
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:37 PM
HI @Vinay49
Change this one line in while loop as:
arryVal.push(gr.user.toString());
The reason is, when you are using (gr.user), its putting the GlideElement object into the array instead of the actual value so it changes as you loop through the records, becoming the value of the next record as you loop. To add the real "value" of the field to the Array, use the above line with toString() to get the actual value.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:38 PM
Hi @Vinay49 always use getValue like below, corrected your code
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:32 PM - edited 03-05-2024 07:33 PM
Hi @Vinay49 ,
var users = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery("group=b8c3923613038b0014145a132244b05a");//update sys_id
gr.query();
gs.print("query success");
while(gr.next())
{
users.push(gr.user+'');//your code change to this line
}
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:37 PM
HI @Vinay49
Change this one line in while loop as:
arryVal.push(gr.user.toString());
The reason is, when you are using (gr.user), its putting the GlideElement object into the array instead of the actual value so it changes as you loop through the records, becoming the value of the next record as you loop. To add the real "value" of the field to the Array, use the above line with toString() to get the actual value.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:38 PM
Hi @Vinay49 always use getValue like below, corrected your code
Harish