Monsieur Winner

MS D365FO || Monsieur D365FO

Technical

Create and post movement journal x++ Ax 2012 / D365FO

Here, a snippet to create a movement journal and automatically post it.

We can use the movement journal to take out item from the inventory for expense.

An example is we have a form where staff can make store request for stationary items such as: Pen, A4 …. Once the request approved, the movement journal is created and posted.

 

JournalCheckPost            JournalCheckPost;

DimensionDynamicDefaultAccount    ledgerDimension;
InventJournalTable         InventJournalTable;
InventJournalTrans         InventJournalTrans;
InventDim                  InventDim;
journalFormTrans           journalFormTrans;
int                        lineNum;
str                        prevId = "";//track previous HeaderID
boolean computed;

ttsbegin;

//Create movevement Jornal Item Header
InventJournalTable.initFromInventJournalName(InventJournalName::find(InventParameters::find().MovementJournalNameId));
InventJournalTable.JournalType = InventJournalType::Movement;
InventJournalTable.JournalId = NumberSeq::newGetNum(InventParameters::numRefInventJournalId()).num();
InventJournalTable.insert();
    
lineNum++;
//Create movevement Jornal Item Lines
InventJournalTrans = null;
InventJournalTrans.initValue();
InventJournalTrans.initFromInventJournalTable(InventJournalTable);
InventJournalTrans.JournalId = InventJournalTable.JournalId;
InventJournalTrans.LineNum = lineNum;
InventJournalTrans.TransDate            =   Gems_SRV.RequestedDate;
InventJournalTrans.Gems_SRV             =   Gems_SRV.RecId;
//InventJournalTrans.TransDate          =   today();
InventJournalTrans.ItemId               =   Gems_SRVLines.ItemId;
InventJournalTrans.Gems_SRVLines        =   Gems_SRVLines.RecId;
InventJournalTrans.Qty                  =   -any2real(Gems_SRVLines.QuantityApproved); // Since we are taking the item out of the inventory, it is negative.
InventJournalTrans.CostPrice            =   InventTableModule::find(Gems_SRVLines.ItemId, ModuleInventPurchSales::Invent).Price;
InventJournalTrans.CostAmount           =   InventJournalTrans.Qty * InventJournalTrans.CostPrice;
ledgerDimension = Gems_ReasonCodes4SRV::getReasonCode(Gems_SRVLines.ReasonCode).LedgerDimension;
InventJournalTrans.LedgerDimension  =   ledgerDimension;
InventDim.InventLocationId              =   Gems_SRVLines.InventLocationId;
InventDim.InventSiteId                  =   Gems_SRVLines.InventSiteId;
InventJournalTrans.InventDimId          =   InventDim::findOrCreate(InventDim).inventDimId;
InventJournalTrans.insert();
computed = true;

if(computed)
{
	// Call the static method to post the journal
	//if(InventJournalCheckPost::newPostJournal(InventJournalTable).validate())
	//InventJournalCheckPost::newPostJournal(InventJournalTable).run();

	JournalCheckPost = InventJournalCheckPost::newPostJournal(InventJournalTable);
	JournalCheckPost.parmTransferErrors(true);
	JournalCheckPost.parmThrowCheckFailed(false);
	JournalCheckPost.run();
	info("Item(s) Transferred Successfully");
}

 

Komi Siabi

Komi Siabi is a Bilingual D365FO Solution architect who loves sharing his knowledge as he works on Both Francophone and Anglophone projects around the globe. He enjoys doing some tiktok videos in his leisure time.

0 thoughts on “Create and post movement journal x++ Ax 2012 / D365FO

  • Your comment is awaiting moderation.

    I’m so in love with this. You did a great job!!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *