Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trying to create array from glideRecord query

Mike D1
Giga Guru
Hi
 
I am working on a business rule and I need to create an array of user's from the below query. However when I test it only prints one sys_id and I know there is a lot more than that?
 
Is anyone able to help me please??
 
Thanks
Mike
 
find_real_file.png
1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Your code is almost fine except one little tiny typo...

Line 6, the ; is causing this. Please remove the ; which should really not be there.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

5 REPLIES 5

Maik Skoddow
Tera Patron
Tera Patron

HI

it prints only the Sys ID because you only has stored the Sys ID at the array (line 7)

If you want to have all field values of the records you can implement like that in line 7:

myArr.push(new SCJSONUtil().getCurrentRecordJSON(gr, new global.GlideRecordUtil().getFields(gr)));

P.S
And correct line 6 as mentioned by Mark

Maik

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Your code is almost fine except one little tiny typo...

Line 6, the ; is causing this. Please remove the ; which should really not be there.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Gaurav Rotke1
Kilo Guru

Hi Mike D,

Please check with that query in the list view, how many records are present, if only one record is present then it will add only one record to array.

Remove semicolon after while() loop, that might help.

Please mark helpful if it helps.

Thank you

Gaurav Rotke

Mark Roethof
Tera Patron
Tera Patron

Also tested your code now with what I mentioned, works fine.

find_real_file.png

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn