Thursday, 30 March 2017

How to get query sum value using X++ code in ax 2012

How to get query  sum value using X++ code in ax 2012 


static void querySumCustAmountMST(Args _args)
{
    Query                               q;
    QueryBuildDataSource                qbds;
    queryBuildRange                     qbr;
    QueryRun                            qr;
    CustTrans                           custTrans;

    q                                   = new Query();

    qbds    = q.addDataSource(tablenum(CustTrans));
    qbds.addSelectionField(fieldNum(CustTrans,AmountMST),SelectionField::Sum);
    qbr     = qbds.addRange(fieldNum(CustTrans,AccountNum));

    qbr.value(strfmt("1001"));
    qr = new QueryRun(q);
    
    while(qr.next())
    {
        custTrans   =   qr.get(tablenum(CustTrans));
        info(strfmt("%1",custTrans.AmountMST));
    }
}


No comments:

Post a Comment