In this article we will see how we can create inventory ownership change journal using X++ code in Microsoft Dynamics Finance & Operations.
We will create a new class named as InventJournalHelper and in this class we will add some methods and using those method we will create and post inventory ownership change journal.
Create a new method named as getInventJournalName in this class to get the invent journal name.
private InventJournalName getInventJournalName(RefRecId _inventJournalNameRecId = 0) { InventJournalName inventJournalName; select firstonly inventJournalName where inventJournalName.RecId == _inventJournalNameRecId; return inventJournalName; }
Create a new method named as getNextLineNumber in this class to get the next line number for inventory ownership change journal.
private LineNumber getNextLineNumber(InventJournalId _inventJournalId) { InventJournalTrans inventJournalLine; LineNumber lineNumber = 0; select maxof(LineNum) from inventJournalLine where inventJournalLine.JournalId == _inventJournalId; lineNumber = inventJournalLine.LineNum; return lineNumber+1; }
Creation of Inventory ownership change journal header
Create a new method named as createInventJournalHeader in this class to create the InventJournalTable record.
public InventJournalTable createInventJournalHeader(RefRecId _inventJournalNameRecId = 0) { InventJournalTable inventJournalHeader; InventJournalName inventJournalName; inventJournalName = this.getInventJournalName(_inventJournalNameRecId); try { ttsbegin; //Header Creation inventJournalHeader.JournalNameId = inventJournalName.JournalNameId; inventJournalHeader.initFromInventJournalName(inventJournalName); inventJournalHeader.JournalId = NumberSeq::newGetNum(InventParameters::numRefInventJournalId()).num(); inventJournalHeader.Description = inventJournalName.Description; inventJournalHeader.JournalType = InventJournalType::OwnershipChange; if (inventJournalHeader.validateWrite()) { inventJournalHeader.insert(); } ttscommit; } catch { System.Exception netExcepn = CLRInterop::getLastException(); Info(strFmt('%1', netExcepn.Message)); } return inventJournalHeader; }
Creation of Inventory ownership change journal line
Create a new method named as initFromHeader in this class to create the InventJournalTrans record by passing the InventJournalTable record, Item Id, Quantity, Warehouse, Site, Location, From Owner, To Owner, Financial Dimension, Batch number as parameters.
public InventJournalTrans initFromHeader( InventJournalTable _inventJournalHeader, ItemId _itemId, InventQtyJournal _inventQtyJournal, InventLocationId _inventLocationId, InventSiteId _inventSiteId, WMSLocationId _wMSLocationId, InventOwnerId _inventOwnerIdIssue, InventOwnerId _inventOwnerIdReceipt, InventSiteLinkedDimensionValueSet _dimensionValueSet, InventBatchId _inventBatchId = '') { InventJournalTrans inventJournalLine; InventDim inventDimIssue; InventDim inventDimReceipt; InventJournalTable inventJournalHeader = _inventJournalHeader; try { //Line Creation inventJournalLine.initValue(); inventJournalLine.initFromInventJournalTable(_inventJournalHeader); inventJournalLine.LineNum = this.getNextLineNumber(_inventJournalHeader.JournalId); inventJournalLine.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()); inventJournalLine.ItemId = _itemId; inventJournalLine.modifiedField(fieldNum(InventJournalTrans, ItemId)); inventJournalLine.Qty = _inventQtyJournal; inventJournalLine.modifiedField(fieldNum(InventJournalTrans, Qty)); inventJournalLine.DefaultDimension = _dimensionValueSet; inventDimIssue.InventSiteId = _inventSiteId; inventDimIssue.InventLocationId = _inventLocationId; inventDimIssue.InventOwnerId_RU = _inventOwnerIdIssue; inventDimIssue.wMSLocationId = _wMSLocationId; inventDimIssue.inventBatchId = _inventBatchId; inventDimIssue = InventDim::findOrCreate(inventDimIssue); inventDimReceipt.data(inventDimIssue); inventDimReceipt.InventOwnerId_RU = _inventOwnerIdReceipt; inventDimReceipt = InventDim::findOrCreate(inventDimReceipt); inventJournalLine.InventDimId = inventDimIssue.InventDimId; inventJournalLine.ToInventDimId = inventDimReceipt.InventDimId; if (inventJournalLine.validateWrite()) { inventJournalLine.insert(); } if (inventJournalLine.RecId != 0) { InventJournalTable::initTotal(inventJournalHeader); inventJournalHeader.update(); } } catch { System.Exception netExcepn = CLRInterop::getLastException(); Info(strFmt('%1', netExcepn.Message)); } return inventJournalLine; }
Posting of Inventory ownership change journal
For posting a inventory ownership change journal we will create another method named as postInventJournal, this takes InventJournalTable record as parameter.
public void postInventJournal(InventJournalTable _inventJournalHeader) { try { JournalCheckPost journalCheckPost; PurchParameters purchParameters; purchParameters = PurchParameters::find(); //Post record journalCheckPost = InventJournalCheckPost::newPostJournal(_inventJournalHeader); journalCheckPost.runOperation(); } catch { System.Exception netExcepn = CLRInterop::getLastException(); Info(strFmt('%1', netExcepn.Message)); } }
For looking over the functional process of Creation of inventory ownership change journal see the article below.
Thank you for reading this article hope you find it useful.
Technical Consultant
References:
I appreciate you sharing this article.Really thank you! Really Great.
whoah this blog is great i love reading your posts. Keep up the great work! You know, many people are looking around for this information, you could aid them greatly.
Generally I do not read article on blogs, but I wish to say that this write-up very compelled me to take a look at and do so! Your writing taste has been amazed me. Thank you, quite nice article.
Hey, thanks for the blog post.Really looking forward to read more. Really Cool.