Hi community,
I'm training some random exercises.
I have this aggregate to use on a table record in order to show the name, description etc
But I want to count the number or orders each customer made. (The sources of the Agg are customer and order).
The problem is: if I perform a count on customer name I get the result but I can't then use the other attributes on the table record anymore.
Any suggestions to solve this issue?
Thanks,
Francisco
Gopi Nath wrote:
Hi Francisco,
Please find the screenshot of the gird where I'm seeing the data. Also attaching sample oml. Not sure if you can publish because of the IPP , but adding it as a reference.
Can u try count by Order Id hiding all the attributes in Order table and then doing a group by on all attributes in customer column this way u will have access to columns that you do group by in table.
Hi Francisco,If I understand what you want... Aggregates don't support the kind of requirement you have. As far as I know, there is no standard SQL that will allow you to do it either.
There may be solutions specific to your database engine, which you'll likely be able to find in an online search or in places like Stack Overflow. Be advised that your application will be bound to that specific database engine.
Alternatively you can split that query in two parts:
This solution will be database engine agnostic, although a bit more database-intensive, as you will perform several queries to get your desired result.Other way that you can look to your problem:
You can perform a single query, sorted by date, and post-process the result in a ForEach, building a new list of Structures with as Attributes the Order and a List of values (or another Structure, if you have more values). This is also a typical method to construct a tree-like data structure for e.g. sending to a REST service (or serving a REST call).
What you'd basically do is keeping track of the current date in the list, and if it's the same as the previous, ListAppend the data to the List Attribute of the structure. When you encounter a new Order, or when you have processed the last item, you ListAppend the top-level Structure to the list used in the Table Records.
Note that for displaying the items, you either need a Web Block (in case you want to display them as a Table Records of their own), or instead of ListAppending to the List Attribute (as I described above), append them to a Text Attribute instead.I hope this help you, if I understood your question Francisco.Cheers,Nuno Verdasca
Nuno Miguel Verdasca wrote:
Hi Nuno,
Thanks for your super detailed answer. Most of the solutions you suggest are a bit complex for me right now but helps a lot so I can study and learn more.
I'll create another aggregate just for the count and place it inside the customer detail page.
Many thanks,
Thanks for your answer Gopi but it didn't work as no results were shown when I published the module and tried it!
Thanks Gopi,
I can publish it but when I open it on the web I get this (slightly different from yours)
But thanks for the example. I'll do another try on my module - maybe I made some mistake!
You don't have to thank Francisco for anything. Also when I have doubts I like someone to teach me, and if we all do this, we all grow.
I am glad, even if it is a little complex for you as you say, that from here you have the solution to solve your problem.
Cheers and merry x-mas sesson,
Nuno Verdasca
I just found out that I can't do it on the customer detail page (which has a form) due to the same reason :)
Well, time to study your solution!
Happy festive season!
I did it again but did not work... maybe I'm making some mistake I don´t know
Francisco wrote:
Is it possible to upload oml that you are working on. I can check if i can find anything
Hi Gopi,
Sorry, you were totally right!
I just figured out the error. I had a filter customerid=customer.id
After I deleted that all went smooth! Thanks for your help!
I'm Glad it worked.