How to iterate with out while loop

Gillerla Rajesh
Tera Contributor

need to iterate records, so insted of while i used for loop .

I tried like this but it's not working any idea provide me.

 

Out put returning undefined 

1 ACCEPTED SOLUTION

Sonam_Tiwari
Kilo Sage

By the way, don't use GlideRecord to get the count.

 

Quite a few issues in the code. Even addQuery isn't correct

 

try this instead

 

var ga = new GlideAggregate('incident');
ga.addQuery('priority', '=', '4');
ga.addAggregate('COUNT');
ga.query();

var count = 0;
if (ga.next()) {
    count = ga.getAggregate('COUNT');
}

// Log or use the count
gs.info('Count of incidents with priority 4: ' + count);

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

View solution in original post

5 REPLIES 5

Sonam_Tiwari
Kilo Sage

Try arr[i].number

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

Not working

 I think in 5th line iam assigned correct or not I don't know, 

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

What's the reason for not using normal construction of while, performing .next() etc.? Or can you explain what you functionally are after? This just looks really odd.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Sonam_Tiwari
Kilo Sage

By the way, don't use GlideRecord to get the count.

 

Quite a few issues in the code. Even addQuery isn't correct

 

try this instead

 

var ga = new GlideAggregate('incident');
ga.addQuery('priority', '=', '4');
ga.addAggregate('COUNT');
ga.query();

var count = 0;
if (ga.next()) {
    count = ga.getAggregate('COUNT');
}

// Log or use the count
gs.info('Count of incidents with priority 4: ' + count);

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.