AX2012 Query Filter Usage

In this Example I am using QueryFilter(new class in AX2012 introduced), So I am using this class to filter the data accordingly which have the outerjoins and get the number of records in each table.

static void Krishh_QueryRangeFilter(Args _args)
{
    Query                   query;
    QueryBuildDataSource    datasource;
    QueryBuildRange         range;
    QueryFilter             filter;//new class in Ax2012
    QueryRun                queryRun;
     int                     counter = 0, totalCounter = 0;
  
    query = new Query();
    datasource = query.addDataSource(tableNum(ChangeOrderJournal));
    datasource = datasource.addDataSource(tableNum(ChangeOrderProduct));
    datasource.joinMode(JoinMode::OuterJoin);
    datasource.relations(true);
    datasource.addLink(fieldNum(ChangeOrderJournal, ChangeOrderNum),
            fieldNum(ChangeOrderProduct, ChangeOrderNum));

// initializes the filter for the specific field.
    filter = query.addQueryFilter(datasource, fieldStr(ChangeOrderProduct, PartNumber));
    filter.value("2-24-05902");

// this is the querybuildRange usage 
 //range = datasource.addRange(fieldNum(ChangeOrderProduct ,   PartNumber));
 //range.value(SysQuery::value(' 2-24-05902 '));
  
    queryRun = new QueryRun(query);
    while (queryRun.next())
    {
        totalCounter++;
        if (queryRun.changed(tableNum(ChangeOrderProduct)))
            counter++;
    }
    info(strFmt("ChangeOrderProduct Counter: %1", counter));
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.