Tuesday, 19 July 2016

InventSum vs InventBatch relations in AX 2012

InventSum -> InventDim = InnerJoin
InventDim -> InventBatch = ExistsJoin 

static void inventSumQuery(Args _args)
{
    Query                   query;
    QueryRun                queryRun;
    QueryBuildDataSource    qbdsInventBatch,
                            qbdsInventDim,
                            qbdsInventSum;

    InventSum               inventSum;
   
    query = new query();
    //InventSum
    qbdsInventSum = query.addDataSource(tableNum(InventSum)); 
    //joins InventDim
    qbdsInventDim = qbdsInventSum.addDataSource(tableNum(InventDim));
    qbdsInventDim.relations(true);
    qbdsInventDim.joinMode(JoinMode::InnerJoin);
    //join InventBatch
    qbdsInventBatch = qbdsInventDim.addDataSource(tableNum(InventBatch));
    qbdsInventBatch.relations(true);
    qbdsInventBatch.joinMode(JoinMode::ExistsJoin);
    //item range   
    qbdsInventSum.addRange(fieldNum(InventSum, ItemId)).value("2664814");  

    queryrun = new QueryRun(query);

    while (queryRun.next())
    {
        queryRun.changed(tableNum(InventSum));
        {
            inventSum = queryRun.get(tableNum(InventSum));
            info(strFmt("ItemId - %1",inventSum.itemid));
        }
    }
}

No comments:

Post a Comment

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...