Skip to main content

Notifications

Create movement journal using X++

Create movement journal using X++

In my this article, I will explain to you about how to create movement journal using x++. Here, you must know about that what is movement journal and for what purpose it is used.

What is movement journal?

It is used to move the inventory “in” and “out” of warehouse for specific reasons and purposes.

If the quantity is negative, it means that the item is taken out of inventory. For example, to take it to a sales show. Value of the inventory must be reduced. It should be considered as an expense from the sales department. In this scenario, expense account can be tagged as an offset account.

If the quantity is positive, it means that the item is brought into inventory from an outside source. For example, a salesperson bring samples into inventory. Cost amount field can be used to enter the value of the item.

What is the use of movement journal?

  • For intake (increase) and outtake (decrease) of the inventory.
  • For Writing-off the inventory to specific main accounts such as “scrap“.
  • To bring in opening inventory balances during system setup, and offset these adjustments to specific ledger accounts.
  • To charge an item to a different department, for example, from prototyping to engineering.

Financial impact:

If the inventory is increase during movement then inventory profit and inventory receipt accounts will get updated with the inventory cost.

If the inventory is decrease during movement then inventory loss and inventory issue accounts will get updated with the inventory cost.

Create movement journal using X++

class CreateMovementJournal
{
    public static void main(Args _args)
    {
        InventJournalTable                  inventJournalTable;
        InventJournalTrans                  inventJournalTrans;
        InventJournalNameId                 inventJournalNameId;
        InventJournalName                   inventJournalName;
        InventDim                           inventDim;     
        DimensionAttributeValueCombination  dimAttrValueCombo;
        int                                 numOfLines = 0;

        ttsbegin;
        //Below code creates journal header
        inventJournalTable.clear();
        inventJournalNameId =  InventJournalName::standardJournalName(InventJournalType::Movement);
        inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalNameId));
        inventJournalTable.insert();

        //Below code creates a single line
        inventJournalTrans.clear();
        inventJournalTrans.initFromInventJournalTable(inventJournalTable);
        inventJournalTrans.TransDate = systemDateGet();
        inventJournalTrans.ItemId = '1000'; //Replace the ItemId according to your data
        inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId));
        inventJournalTrans.Qty = 1; //Replace the Qty according to your data
        inventdim.InventSiteId = '1'; //Replace the InventSiteId (Site) according to your data
        inventdim.InventLocationId = '11'; //Replace the InventLocationId (Warehouse) according to your data
        inventJournalTrans.InventDimId = InventdIm::findOrCreate(inventDim).inventDimId;

        dimAttrValueCombo.clear();
        select firstonly RecId from  dimAttrValueCombo
            where dimAttrValueCombo.MainAccount == MainAccount::findByMainAccountId("110110").RecId //Replace the MainAccountId according to your data
            && dimAttrValueCombo.DisplayValue == '110110';  //Replace the MainAccountId according to your data
          
        inventJournalTrans.LedgerDimension = dimAttrValueCombo.RecId;

        //Insert line to movement journal if quantity is non-zero
        if(inventJournalTrans.Qty > 0)
        {
            numOfLines++;
            inventJournalTrans.insert();
        }

        //updating number of lines field at header level of Movement Journal
        inventJournalTable.NumOfLines = numOfLines;
        inventJournalTable.update();
        ttscommit;

        info(strFmt("Movement Journal ID: %1", inventJournalTable.JournalId));
    }

}

The above code snippet will create the movement journal. Please note that I have tested this code in D365FO, I hope it will work on AX 2012 as well.

So, in this way you can create movement journal using X++ in D365FO. Moreover, if this helps you, please Like, Comment and Share to help other people.

If you found any ambiguity or a better solution, please feel free to ask.

See also:

Download code: Click here

Website: Click here

Blog: Click here

YouTube: Click here

GitHub: Click here

Facebook: Click here

The post Create movement journal using X++ appeared first on NevoiTech Blog.

Comments

*This post is locked for comments