Find unique entries, count them than iterate for each row in html table.
Hello,
I have data within my form, we'll call it base_data,
in the following format:
Reciept_Type
(string/picklist) |
status | agentid (picklist
stored .toString() in input.agentid, thus stored as record
ID) |
| digital |
active | 23115441 |
| no receipt
| inactive | 231154323 |
| digital | active | 231154323 |
| paper | active | 231154323 |
| no receipt | active | 231154323 |
| no receipt | active | 231154323 |
| paper | inactive | 23115499 |
| no receipt | active | 231154102
|
| paper | inactive | 231154323 |
| no
receipt | inactive | 23115499899 |
I have an html view in this format with a parameter called
AGENTID being passed, which dictates the view of the html
table:
|
Tickets for agent 231154323
|
| Receipt_Type
| Receipt Count |
| Digital | 1 |
| Paper
| 3 |
| No Receipt | 2 |
I am attempting to use the following code to fetch,
display and sum the unique receipt types : This is the
code that i have tried using:
-
-
<table>
-
<tbody>
-
<tr>
-
<th>Tickets for agent 323</th>
-
</tr>
-
<tr>
-
<th>Receipt Type</th>
-
<th>Receipt
Count</th>
-
</tr>
- <% for each count_pmt in base_data
[(AGENTID == input.AGENTID.toLong())]
-
{
- RCPT_NAME =
count_pmt.Receipt_Type;
-
-
RCPT_UNIQUE = base_data[( Receipt_Type ==
RCPT_NAME && AGENTID == input.AGENTID.toLong()
)].distinct(Receipt_Type);
-
-
RCPT_COUNT = base_data[( Receipt_Type ==
RCPT_NAME && AGENTID == input.AGENTID.toLong() )].count();
%>
-
-
<tr>
-
<td style="text-align:
left;"><%=RCPT_UNIQUE%></td>
-
<td><span
style="font-size:
small;"><%=RCPT_COUNT%></span></td>
-
</tr>
-
<%}%>
-
</tbody>
-
</table>
However, the code returns the following:
| Tickets
for agent
231154323 |
| Reciept_Type | Receipt Count |
| no receipt
| 3 |
| digital | 1 |
| paper | 2 |
| no receipt
| 3 |
| no receipt | 3 |
| paper | 2 |
edit: It fetches the tickets that match the AGENTID no
problem, however instead of listing the unique entries and their
corresponding count just once, the row iterates for every single
record than lists the records count.
Is there a method other than aggregate>distinct to return the
unique values or am i missing something with this code?