GlideAggregate Question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 10:49 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 10:37 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 07:50 AM
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.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 12:37 PM
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.