Implementing Advanced Filter/Sort functionality

I’m working in AX 2009 using a duplicate of the InventOnhandItem form, which has more than 90% of my needs for a particular project.

When this form is opened and the user clicks the “Advanced Filter/Sort” button, then right-clicks on the “On-hand inventory” table (the InventSum) and chooses n:1 > Items (Item number). If this is Added to the range with “Items” listed under Table, and “Item group” listed under Field, then the user can narrow down the criteria field with an item group of say “Finished Goods”, which will display only finished goods items in the grid.

I have been tasked with adding a filter pane to the form, so that the user will be presented with the choice of selecting from one of the item groups available. I added a Group control to the form and placed a StringEdit control in this group. I set its ExtendedDataType to “ItemGroupId”, so that the above choices show up in the control.

I followed the suggestions found in an article titled “How to: Add a Filter to a List Page”, which I based my code on. However, after modifying the code, it still doesn’t give me the same functionality as the “Advanced Filter/Sort”. I need to know how to duplicate its functionality, including the ability to select a “Many-to-One” n:1 to add the above stated capability of Items, Item group, etc.

Can someone suggest how to duplicate the abilities of the “Advanced Filter/Sort”? Thank you in advance.

Hi,

Try building cross references and then test this functionality.

Hello Harish. I’m not sure what you mean by building cross references. However, I reworked my code and I’m about 99% of the way there, with one small issue. Let me explain the steps I’ve taken, then I’ll explain the remaining issue.

In my classDeclaration I defined a range object like so. QueryBuildRange mItemGroupId;

Then in my form datasource init method I added the following code.

QueryBuildDataSource inventSumDS; //added 8/23/11
;

super();

inventSumDS = inventSum_DS.query().addDataSource(tableNum(InventTable)); //added 8/23/11
mItemGroupId = inventSumDS.addRange(fieldNum(InventTable, ItemGroupId)); // added 8/23/11

element.inventDimSetupObject().initQueryInventSum(inventSum_DS); //this was the existing line in the InventOnhandItems form.

Next in my executeQuery method my code is as follows

;
mItemGroupId.value(queryValue(ItemGroupFilter.valueStr())); //added 8/23/11 (ItemGroupFilter is my StringEdit control in a group control with its ExtendedDataType set to ItemGroupId)

element.inventDimSetupObject().modifyQuery(inventSum_DS,inventDim_DS); //this was the existing line in the InventOnhandItems form.

super();

Finally, I overrode the Modified method of my StringEdit ItemGroupFilter with the following…

boolean ret;

ret = super();

inventSum_DS.executeQuery();

return ret;

Now when I open my form (which is a duplicate of the InventOnhandItems form) I have the grid populated as normal. My StringEdit control (ItemGroupFilter) is blank, waiting for me to select an ItemGroup. I select Finsh Good from the list. If I click on the Advanced Filter/Sort button, I can verify that Items is listed under Table, Item group is listed under Field. However, under Criterial it reads Finsh\ Good rather than Finsh Good and my Grid does not refresh like the grid does in the InventOnhandItems form.

Can anyone suggest why, although I have gotten this close to adding a specific filter for item groups, the data grid will not refresh? I even tried adding this code to the modified method of my StringEdit control…

boolean ret;

ret = super();

element.lock();
inventSum_DS.executeQuery(); //added 8/23/11
inventSum_DS.refresh();
element.unLock();

return ret; But still nothing.

Please help!

The problem is finally solved. What I needed to do was to add the InventTable table to the data sources under InventSum, perform an Inner Join of this table to InventSum and set the JoinSource to InventSum.

Then after modifying the code slightly, the filter began working correctly as desired by filtering by ItemGroup and refreshing the data grid.