Not able to push sys ids

ObuM
Giga Contributor

Tryin to crate array of sysids. Don't know why its not getting.

var gr = new GlideRecord('sys_user');
gr.query();
var users = [];
while(gr.next()){
    users.push(gr.sys_id);
}
gs.info(users);
2 ACCEPTED SOLUTIONS

maheshkhatal
Mega Sage

Hello,

    You have to make correction to from gr.sys_id to gr.sys_id.toString(), because in gr.sys_id you are still referring to the same object. Also the best practice is to use the getter here like gr.getUniqueValue().

See the correction below: 

var users = [];
var gr = new GlideRecord('sys_user');
gr.query();
while(gr.next()){
  users.push(gr.sys_id.toString());
  //users.push(gr.getUniqueValue()); 
 }
gs.info(users);

Thank you,

Mahesh.

View solution in original post

Juhi Poddar
Kilo Patron

Hello @ObuM 

Thank you for marking my response helpful.

As per the new community policy, you can mark multiple accepted solution.

Can you please mark the solution as accepted, it will help future readers to locate the solution easily in community.

 

Thank You 

Juhi Poddar 

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@ObuM 

this will work

var gr = new GlideRecord('sys_user');
gr.query();
var users = [];
while(gr.next()){
users.push(gr.getUniqueValue());
}
gs.info(users.toString());

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@ObuM 

Thank you for marking my response as helpful.

As per new community feature you can mark multiple responses as correct.

Also my response was the 1st to provide you the correct solution.

If my response helped please mark it as well so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@ObuM 

Could you mark my response correct as well as I also provided the correct solution?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ranjit Nimbalka
Mega Sage

Hi @ObuM ,

please try below script:-

var gr = new GlideRecord('sys_user');
gr.query();
var users = [];
while(gr.next()){
    users.push(gr.sys_id.toString());
}
gs.info(users);

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

Regards,

Ranjit