Tuesday, July 5, 2011

To find MAX, MIN, COUNT of any table in AX 2009

Hi,
Below is the code snipet to find out the MAX value of a particular field in a particular table.
static void MaxValueTest(Args _args)
{
    str maxValue(TableId tableId, FieldId fieldId)
    {
        QueryRun qr = new QueryRun(new Query());
        qr.query().addDataSource(tableId).addSelectionField(fieldId, SelectionField::Max);
        return qr.next() ? any2str(qr.get(tableId).(fieldId)) : '';
    }
    ;
    info(maxValue(tableNum(BOMTable), fieldNum(BOMTable,BOMId)));
}

In the above example the "SlecttionField" has the mulitple static filed which can give you more choices.

Thanks,
/Ashlesh

No comments:

Post a Comment