Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Thursday, May 2, 2019

Clear multiple open statements using X++ in ax 2012

static void ClearStatement(Args _args)
{
    RetailStatementTable    statementTable;

    while select forUpdate statementTable
        order by calculatedDate desc
            where (statementTable.storeId == '092')
                //&& statementTable.statementId > '091-000311'//mkDate(20,12,2018)
    {
        statementTable.unmarkTransactions();
        statementTable.unmarkPosBatches();

        ttsBegin;
        statementTable.recalculate = NoYes::No;
        statementTable.calculatedDate = dateNull();
        statementTable.CalculatedLines = 0;
        statementTable.calculatedTime = 0;
        //statementTable.stmtCalcInfoLog = "";
        //statementTable.stmtPostInfoLog = "";

        statementTable.doUpdate();
        ttsCommit;
    }
    info("Done");
}

Sunday, April 21, 2019

How to Unregister or deregister all items in purchase order using X++ (Via Code) in ax 2012

Hi Guys,
I have registered PO lines using Item arrival journal.
Need to unregister more that 500 lines. below are lines of code to unregister item: -

static void testUnregistration(Args _args)
{
    PurchTable purchTable;
    InventTrans inventTrans;
    InventTransOrigin inventTransOrigin;
    PurchLine   purchLine;
    InventDim inventDim;

    TmpInventTransWMS tmpInventTransWMS;

    InventTransWMS_register inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);

    while select purchLine where purchLine.PurchId == this.PurchId
    {
        select inventTransOrigin
        where inventTransOrigin.ReferenceId == purchLine.PurchId
        && inventTransOrigin.ItemId == purchLine.ItemId;

        while select inventTrans
        where inventTrans.InventTransOrigin == inventTransOrigin.RecId
        {
            select inventDim where inventDim.inventDimId == inventTrans.inventDimId;

            if (inventTrans.StatusReceipt == StatusReceipt::Registered)
            {
                inventTransWMS_register.createFromInventTrans(inventTrans, inventDim);
                inventTransWMS_register.updateInvent(purchLine);
            }
        }
    }
}