How to loop through a table?

zaryabro1
Giga Contributor

How do I loop through a table, I want to get specific data from a table based on a condition and put it into an array.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Something like this

var arr = [];

var gr = new GlideRecord('incident');

gr.addQuery('active', true);

gr.query();

while(gr.next()){

arr.push(gr.getValue('number'));

}

gs.info(arr);

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Can you provide a bit more info of what you are after?

For example should this be Client Side? Server Side? Is this for a certain form, integration, etc.? First guess would be you could just perform a GlideRecord query, though what is your question about more specifically?

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

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 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

Hey @Mark Roethof,

I am writing a Business Rule. I got the table through:

var gr = new GlideRecord(<table name>);

 

Now, I want to loop through it and get data from a column based on a condition.

Hi There,

Can you tell the condition more specifically.

Below are some examples on glide record query:

 

Glide Record

 

Please mark this answer as correct and helpful if it resolves the query and helpful alone if it lead you in right direction.

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Something like this

var arr = [];

var gr = new GlideRecord('incident');

gr.addQuery('active', true);

gr.query();

while(gr.next()){

arr.push(gr.getValue('number'));

}

gs.info(arr);

Regards
Ankur

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