GlideAggregate Question

Rishabh Khare
Giga Contributor

Hi Everyone,

I am new to this can anyone please tell me why we use if block while counting record using GlideAggregate.

 

var count = new GlideAggregate('u_test');
count.addAggregate('COUNT');
count.query();
var computer=0;
if(count.next())
    {
        computer=count.getAggregate('COUNT');
        gs.info(computer);
        
    }
    What this line if(count.next()) says When I removed this if block then also answer is same.

var count = new GlideAggregate('u_test');
count.addAggregate('COUNT');
count.query();
var computer=0;
count.next();

   computer=count.getAggregate('COUNT');
   gs.info(computer);
        
    
        

7 REPLIES 7

Thanks for your response Yousaf can you please tell me how you came to know that it is returning one record I mean is there any code defined for GlideAggregate within instance which I can also read to understand concept in better way.

Hi Rishabh,

If is a conditional statement when the condition in if is true code inside will run once

And while is a loop code inside will run untill statement after while is true it will stop when while statement become false.

For Example

if (x > y)
{
   // this will only happen once
}
while (x > y)
{
  // this will keep happening until the condition is false.
}

 


***Mark Correct or Helpful if it helps.***

Kamil Surtel
Mega Guru

While returns multiple records, if returns just the first one. It can be useful if you use, for example, use orderByAggregate and addTrend and want to get just the first result in a certain time period.

Also, in your particular example, if is not necessary.