Create and post the Adj Journal in D365FO using x++.
private void createPostAdjJournal(ItemId _itemid, InventLocationId _warehouse, WMSLocationId _location, Qty _qty, WHSLicensePlateId _licensePlateId, InventBatchId _batch) { InventJournalTable inventJournalTable; InventJournalTrans inventJournalTrans; InventJournalNameId inventJournalName; InventDim inventDim; JournalCheckPost journalCheckPost; WHSLicensePlate whsLicensePlate; InventLocation inventLocation; ttsbegin; whsLicensePlate = WHSLicensePlate::createLicensePlate(_licensePlateId, true, ""); inventJournalName = InventJournalName::standardJournalName(InventJournalType::LossProfit); inventJournalTable.clear(); inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName)); inventJournalTable.insert(); //<Creation of journal Line> inventJournalTrans.clear(); inventJournalTrans.initFromInventJournalTable(inventJournalTable); inventJournalTrans.TransDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()); inventJournalTrans.ItemId = _itemid; inventJournalTrans.initFromInventTable(InventTable::find(_itemid)); inventJournalTrans.Qty = _qty; inventDim.wMSLocationId = _location; inventDim.InventLocationId = 'ware house'; inventDim.InventSiteId = InventLocation::find('ware house').InventSiteId; inventDim.InventSizeId = 'Blank'; //TODO inventDim.LicensePlateId = whsLicensePlate.LicensePlateId; inventDim.inventBatchId = _batch; //you can add here as many inventory dimensions as required inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId; inventJournalTrans.insert(); //<Post Journal> journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable); journalCheckPost.runOperation(); ttscommit; info(strFmt('Journal %1 has been posted',inventJournalTable.JournalId)); }
Keep Daxing!!
No comments:
Post a Comment