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.

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

Hi @Sonam_Tiwari @Mark Roethof 

I am trying with for loop, insted of while(gr.next())

 

In interview they asked me this question with out while how iterate elements and print the numbers so I said with for loop keep elements in array and loop with for. So now I am trying with this how can achive.