31) How to create and post Inventory Movement Journal through x++ in D365 FO

One of the most common requirements these days is to create Inventory Movement Journal through code. Mostly when the input is coming from another 3rd Party application.

Here is the code show below :-



       InventJournalTable              inventJournalTable;
       InventJournalTrans              inventJournalTrans;
       InventJournalNameId             inventJournalName;
       InventDim                            inventDim;
       JournalCheckPost               journalCheckPost;
     

       // Creation of Inventory Journal Header     

        inventJournalTable.clear();

        inventJournalName =                                                                                                         InventJournalName::standardJournalName(InventJournalType::Movement);
        inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName ));

        inventJournalTable.insert();

     

        //Creation of Inventory Journal Lines

        inventJournalTrans.clear();

        inventJournalTrans.initFromInventJournalTable(inventJournalTable);

        inventJournalTrans.TransDate = systemDateGet();

        inventJournalTrans.ItemId = “Product88987”;

        inventJournalTrans.initFromInventTable(InventTable::find(“Item0001”));

        inventJournalTrans.Qty = 11;

        inventDim.InventSiteId  = 'A1';

        inventDim.InventLocationId = 'Loc1';

        inventDim.wMSLocationId = ‘WS1’;

        inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;

        inventJournalTrans.insert();

     

        //Posting the journal

        journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
        journalCheckPost.run();

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++