- 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:29 AM
Hi
If you used groupBy() in GlideAggregate, it will give you the COUNT of group with unique Values.
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:47 AM
Hi Smudge,
Thanks for the quick response. what I'm not able to understand is its function in code .
I understand it'll give a unique value.
So for example if i had say 30 parent field with unique value, 25 child with unique value and 3 types of relationships
so using the same code
agg.groupBy('parent'); // answer is 30
agg.groupBy('type'); // answer is 3
agg.groupBy('child'); // answer is 25
does these group by cascade from line to line?
like
30 Unique parent ------> out of these 30 unique parent 5 unique child (list view now has 5 records)------------------> out of these 5 records 2 "types".
so i'm left with two groups?
Thanks
- 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 05:51 AM
Hi Smudge,
so this whole groupBy is just to eliminate the records where parent, child and type are not empty .right?
Otherwise, it'll anyway show count 558 , since GlideAggregate will check all the records anyway.