- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 03:20 AM
Hi Experts,
i was trying to clean up duplicate CI, and i found that my code works if i group By all three category (parent, child & type) and not if i just groupBy one category.
May i ask what groupBy(), does here exactly? why is this code is not working without these groupings
var agg = new GlideAggregate('cmdb_rel_ci');
agg.addQuery(encodedQuery);
agg.setLimit(batch);
agg.groupBy('parent');
agg.groupBy('type');
agg.groupBy('child');
agg.addAggregate('COUNT');
agg.addHaving('COUNT', '>', '1'); // if Query finds more than 1 record with same parent, type and child
agg.query();
is the groupBy here is same as the screenshot in list view?
if so how can we have group by different category ?
I'm still a noob and trying to understand the platform.
I'll be grateful if you can explain that.
Regards,
Varun Sharma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 04:26 AM
Hi
No, It will take all.
Example:
In my PDI, I have total 558 CIs.
agg.groupBy('parent'); // answer is 180
agg.groupBy('type'); // answer is 19
agg.groupBy('child'); // answer is 189
If I grouped all three fields.
Then i'm getting 558.
Here what happening is, If you have atleast one Parent or type or child. It will count.
If I grouped only one field(parent).
Then I'm getting 180.
Here what happening is, It will take only parent field which are not empty.
If my response is helpful, then Please mark as Correct Answer/Helpful.
Please check and let us know.
Thanks:)
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 03:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 03:51 AM
Hi Rahul ,
I did go through with this. didn't understand it much, that's why i decided to post the question.
here in code snippet you'll see the groupBy is used just once.
in my code it's used thrice, i'm trying to understand how multiple groupby line by line impact the result.
Regards,
Varun Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 04:23 AM
Hi Varun
If you will use multiple groupby then it filters out more specifically.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 03:37 AM
Hi
groupBy(String name)
May be called numerous times to set multiple group fields.
Name | Type | Description |
---|---|---|
name | String | Name of the field. |
Type | Description |
---|---|
void | Method does not return a value |
Scoped equivalent:
To use the groupBy() method in a scoped application, use the corresponding scoped method: Scoped GlideAggregate - groupBy(String name).
Example:
var count = new GlideAggregate('incident');
count.addAggregate('MIN', 'sys_mod_count');
count.addAggregate('MAX', 'sys_mod_count');
count.addAggregate('AVG', 'sys_mod_count');
count.groupBy('category');
count.query();
while (count.next()) {
var min = count.getAggregate('MIN', 'sys_mod_count');
var max = count.getAggregate('MAX', 'sys_mod_count');
var avg = count.getAggregate('AVG', 'sys_mod_count');
var category = count.category.getDisplayValue();
gs.log(category + " Update counts: MIN = " + min + " MAX = " + max + " AVG = " + avg);
}
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 03:48 AM
Hi Sandeep,
here in code snippet you'll see the groupBy is used just once.
in my code it's used thrice, i'm trying to understand how multiple groupby line by line impact the result.
Regards,
Varun Sharma