Getting user filter values from a grid

I’m working on a form customization right now, on the InventOnhandItem form. As part of this customization, I need to retrieve any values that the user has typed into the “ctrl-g” filter fields.

I thought that maybe I could figure this out by looking at the query, but these filters don’t seem to be added to the query. (Either that, or I’m looking at the wrong query.)

I’m wondering if there’s a way to just iterate through the filter fields and pull the values from them, but I haven’t been able to figure that out. Any help would be appreciated. Thanks!

I probably know what’s the problem. First of all, try this code:


This first one won’t display user-defined filters, but the latter one should. The code above is just a shortcut for this code:


FormDataSource.query() returns definition of the form query, while FormDataSource.queryRun().query() is the actual query including changes done by user.

Thanks! That’s definitely got me past the first hurdle.

info(InventSum_ds.queryRunQueryBuildDataSource().toString()); gives me, for instance:

SELECT WITH FORCE_PLACEHOLDERS FIRSTFAST INDEXISHINT SUM(PostedQty), SUM(PostedValue), SUM(PhysicalValue), SUM(Deducted), SUM(Registered), SUM(Received), SUM(Picked), SUM(ReservPhysical), SUM(ReservOrdered), SUM(OnOrder), SUM(Ordered), SUM(Arrived), SUM(QuotationReceipt), SUM(QuotationIssue), SUM(PhysicalInvent), SUM(AvailPhysical), SUM(AvailOrdered)
FROM InventSum(InventSum) USING INDEX ClosedItemDimIdx
GROUP BY InventSum.ItemId, InventDim.InventSizeId ORDER BY InventSum.ItemId ASC
WHERE ((Closed = 0))
USING INDEX DimIdIdx ON InventSum.InventDimId = InventDim.inventDimId
WHERE ((InventSum(InventSum).ItemId LIKE N’116*’))
AND ((InventDim(InventDim).InventSizeId = N’Acad’))

…which has my user filters there at the end.

My next issue, though, is figuring out how to access those values from the ‘where’ clause.

I thought I could use .findRange() or .rangeCount() & .range(x), but I’m only getting the ‘closed=0’ range from those. I’m obviously still doing something wrong somewhere…

This part changed in AX2012, because filters are used instead of ranges (see a bit more about them here).

You can get filter values by this code:

Query q = InventSum_ds.queryRun().query();
QueryFilter qf;
int i;

for (i = 1; i <= q.queryFilterCount(); i++)
    qf = q.queryFilter(i);
    info(strFmt("%1: %2", qf.field(), qf.value()));

Thanks much Martin! That’s definitely got me on the right track now.

boss , would you mind letting me know what should be used in place of “QueryFilter” in AX2009 when i intented to have the filtered field and value.


May i have a piece of code where QueryBuildRange is used to get the filtered value [ctrl+g] of grid control which would be displayed again after executeQuery() of data source. Any sort of help would be highly appreciated. Thanks in Advance.

finally i got the way and solved it with the following code

public void executeQuery()

QueryBuildRange qbr;

qbr = this.queryRun().query().dataSourceTable(tablenum(WAXInventSumDim)).findRange(fieldnum(WAXInventSumDim,PhysicalInvent));
SysQuery::findOrCreateRange(this.queryRun().query().dataSourceTable(tablenum(WAXInventSumDim)), fieldnum(WAXInventSumDim, PhysicalInvent)).value(’!0’);