Group by in form's datasource

Hi,

The below given is a screen shot of the records available in a table. I programmatically want to filter the records so that records if grouped by item code having maxof item version would be displayed.

3487.Untitled.jpg

So that the expected output is:

Item Code Item Version
ITEM1 3
ITEM2 2
ITEM3 6

I know that we can achieve this by grouping by Item Code at the data source and adding a display method to display the version, but want suggestions to do it programmatically.

The easiest approach is just to model the query in AOT (group by ItemCode, Fields Dynamics=No, Right-click fields > New > MAX > ItemVersion), if your version of AX supports it. If you need it in runtime, you have to change form’s query - use addSelectionField(…, SelectionField::Max) and addGroupByField(…).

Hi Martin,

Thank you for the hints, I’ll try them and post the result soon.

As expected, it worked like a charm!!! Thanks a tonne!!!

HI martin ,

How to groupby a display method in query in AOT in ax 2012.?

Thanks in advance…

Hi Alonso,

could you please create a new thread (this has already been answered) and explain a bit more about what you’re trying to do and what’s the problem?

Thanks.