Search This Blog

Wednesday, May 23, 2012

AX2012 QueryHavingFilter usage

In this Example I am showing how to QueryHavingfilter(New class in AX2012) class
Before seeing this post please see my previous post explains the QueryFilter Class

If we want to get this following Query format from X++ then we can use the QueryHavingFilter class.
Select VendGroup,Count(*) from VendTable group by VendGroup having Count(*) >2

static void Krishh_HavingQueryFilter(Args _args)
    Query                   query;
    QueryBuildDataSource    datasource;
    QueryBuildRange         range;
    QueryHavingFilter       havingFilter;
    QueryRun                queryRun;
    int                     counter = 0, totalCounter = 0;
    VendTable               vendTable;
    query = new Query();
    datasource = query.addDataSource(tableNum(VendTable));
    datasource.addSelectionField(fieldNum(VendTable, RecId),
    datasource.addGroupByField(fieldNum(VendTable, Vendgroup));
    havingFilter = query.addHavingFilter(datasource, fieldStr(VendTable, RecId),
    queryRun = new QueryRun(query);
    while (
        vendTable = queryRun.getNo(1);
        info(strFmt("Group %1: %2", vendTable.VendGroup, vendTable.RecId));

1 comment:

  1. I am still in the phase of studying QueryFilter Class usage. This is our homework. There are lot of things I need to learn from this one. Thanks for sharing!


Thanks for visiting my blog,
I will reply for your comment within 48 hours.