hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Sunday, August 30, 2020

Query Classes in AX 2012

 static void queryClasses(Args _args)

{


    date            dateFrom    = 01\01\2012 ;

    date            dateTo      = 31\01\2012 ;

    Query query;

    QueryBuildDataSource queryBuildDataSource;

    QueryBuildRange queryBuildRange,qbr;

    QueryBuildFieldList  qbfl       ;

    QueryRun queryRun;

    CustTrans custTrans;

    ;

    query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTrans));

    queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTrans,AccountNum));

    qbr = queryBuildDataSource.addRange(fieldNum(CustTrans,TransDate));

    //queryBuildRange.value("Us-010,us-020  ");

    qbr.value(SysQuery::range(dateFrom, dateTo));

    queryBuildDataSource.addSortField(fieldNum(CustTrans,AccountNum));

    //queryBuildDataSource.addSortField(fieldNum(CustTrans,Invoice));

    //Greater than or less than values passing

   // queryBuildRange.value('us-010..us-020');

    //passing like operator 

   // queryBuildRange.value('*Us*');

    //not like

    queryBuildRange.value('!*Us*');

    queryBuildDataSource.addSelectionField(fieldnum(CustTrans,RecId),SelectionField::Count);

    queryBuildDataSource.orderMode(OrderMode::GroupBy);

    info(queryBuildDataSource.toString());

    queryRun = new QueryRun(query);

    while (queryRun.next())

    {

    custTrans = queryRun.get(tablenum(CustTrans));


    info (strfmt(" Customer Account  :%1 Group : %2",custTrans.AccountNum,custTrans.RecId ));


    }

}

No comments:

Post a Comment