- 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
Tuesday
i need answer
to my question why we use GroupBy in serviceNow and Use ?
