GlideAggregate COUNT on a reference field returns 1 instead of the number of distinct records
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
26m ago
Hi,
You can fix this by using COUNT(DISTINCT instead of COUNT with a field name. addAggregate('COUNT', 'field') does not count distinct values, so a query like “how many servers have this software installed” comes back as 1 (or another wrong number) even when thousands of servers match.
Step 1: Find the existing aggregate
Find:
Step 2: Replace it with COUNT(DISTINCT
Replace with:
Note that the same string 'COUNT(DISTINCT' (with the open parenthesis, no closing one) must be used in both addAggregate and getAggregate.
Step 3 (optional): Get rows and distinct counts in one query
Result: in our case the detail screen showed “1 server” for a package that was actually installed on more than 12,000 servers. After the change, the count matched the list view.
If this helped, please mark it as Helpful 👍
0 REPLIES 0