In this article we will see how we can create consignment replenishment order using X++ code in Microsoft Dynamics Finance & Operations.
We will create a new class named as ConsignmentReplenishmentOrderHelper and in this class we will add some methods and using those method we will create and post product receipt of consignment replenishment order.
Create a new method named as getOrderNumber in this class to get the new order number from number sequence.
public ConsignmentReplenishmentOrderNumber getOrderNumber() { NumberSeq num = new NumberSeq(); num = NumberSeq::newGetNum(PurchParameters::numRefReplenishmentOrder()); return num.num(); }
Create a new method named as getDeliveryAddressFromWH in this class to get the logistics postal address from the warehouse name.
private LogisticsPostalAddress getDeliveryAddressFromWH(InventLocationId _locationId) { InventLocation inventLocation; LogisticsLocation logisticsLocation; LogisticsLocationRole logisticsLocationRole; LogisticsPostalAddress logisticsPostalAddress; InventLocationLogisticsLocation inventWHLogisticsLocation; InventLocationLogisticsLocationRole inventLocationLogisticsLocationRole; select logisticsPostalAddress join logisticsLocation where
logisticsPostalAddress.Location == logisticsLocation.RecId join inventWHLogisticsLocation where inventWHLogisticsLocation.Location == logisticsLocation.RecId join InventLocationLogisticsLocationRole where inventLocationLogisticsLocationRole.LocationLogisticsLocation == inventWHLogisticsLocation.RecId join logisticsLocationRole where
logisticsLocationRole.RecId == InventLocationLogisticsLocationRole.LocationRole join inventLocation where inventLocation.RecId == inventWHLogisticsLocation.InventLocation && inventLocation.InventLocationId == _locationId && logisticsLocationRole.Type == LogisticsLocationRoleType::Delivery && inventWHLogisticsLocation.IsPrimary == NoYes::Yes; return logisticsPostalAddress; }
Creation of Consignment Replenishment Order Header
Create a new method named as createConsignmentReplenishmentOrderHeader in this class to create the ConsignmentReplenishmentOrderHeader record by passing the VendTable record and DeliveryDate.
public ConsignmentReplenishmentOrderHeader createConsignmentReplenishmentOrderHeader(VendTable _vendTable, Date _shipDate) { ConsignmentReplenishmentOrderHeader consignmentJournalHeader; LogisticsLocation location; consignmentJournalHeader.ReplenishmentOrderNumber = this.getOrderNumber(); consignmentJournalHeader.OrderVendorAccountNumber = _vendTable.AccountNum; consignmentJournalHeader.DefaultReceivingSiteId = _vendTable.InventSiteId; consignmentJournalHeader.DefaultReceivingWarehouseId = _vendTable.InventLocation; consignmentJournalHeader.RequestedDeliveryDate = _shipDate; consignmentJournalHeader.ConfirmedDeliveryDate = _shipDate; consignmentJournalHeader.DeliveryPostalAddress = this.getDeliveryAddressFromWH(_vendTable.InventLocation).RecId; location = LogisticsLocation::find(LogisticsPostalAddress::findRecId(consignmentJournalHeader.DeliveryPostalAddress).Location); consignmentJournalHeader.DeliveryAddressName = location.Description; consignmentJournalHeader.defaultField(fieldnum(ConsignmentReplenishmentOrderHeader, AddressRefRecId)); consignmentJournalHeader.defaultField(fieldnum(ConsignmentReplenishmentOrderHeader, AddressRefTableId)); consignmentJournalHeader.insert(); return consignmentJournalHeader; }
Creation of Consignment Replenishment Order Line
Create a new method named as createConsignmentReplenishmentOrderLine in this class to create the ConsignmentReplenishmentOrderLine record by passing the ConsignmentReplenishmentOrderHeader record, Line Number, Item Id, Quantity, Unit ID.
public void createConsignmentReplenishmentOrderLine(
ConsignmentReplenishmentOrderHeader _header,
TradeLineNumber _lineNum,
ItemId _itemId,
ConsignmentReplenishmentQuantity _quantity,
UnitOfMeasureSymbol _unitId) { ConsignmentReplenishmentOrderLine replenishmentOrderLine; InventDim inventDimPurchSetup,inventDimItemLocation, inventDim; InventItemPurchSetup inventItemPurchSetup; InventItemLocation inventItemLocation; replenishmentOrderLine.DeliveryAddressName = _header.DeliveryAddressName; replenishmentOrderLine.DeliveryPostalAddress = _header.DeliveryPostalAddress; replenishmentOrderLine.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num(); replenishmentOrderLine.ItemId = _itemId; replenishmentOrderLine.LineNumber = _lineNum; replenishmentOrderLine.ReplenishmentQuantity = _quantity; replenishmentOrderLine.ReplenishmentInventoryQuantity = _quantity; replenishmentOrderLine.RemainingInventoryPhysicalQuantity = _quantity; replenishmentOrderLine.RemainingReplenishmentPhysicalQuantity = _quantity; replenishmentOrderLine.ReplenishmentOrderLineStatus = ConsignmentReplenishmentOrderLineStatus::OpenOrder; replenishmentOrderLine.ReplenishmentOrderNumber = _header.ReplenishmentOrderNumber; replenishmentOrderLine.ReplenishmentUnitId = _unitId; replenishmentOrderLine.ConfirmedDeliveryDate = _header.RequestedDeliveryDate; replenishmentOrderLine.RequestedDeliveryDate = _header.RequestedDeliveryDate; replenishmentOrderLine.defaultField(fieldnum(ConsignmentReplenishmentOrderLine, AddressRefRecId)); replenishmentOrderLine.defaultField(fieldnum(ConsignmentReplenishmentOrderLine, AddressRefTableId)); inventDimPurchSetup = InventDim::find(InventItemPurchSetup::find(_itemId,inventDim::inventDimIdBlank()).InventDimIdDefault); inventDimItemLocation.InventLocationId = inventDimPurchSetup.InventLocationId; inventDimItemLocation = InventDim::findOrCreate(inventDimItemLocation); inventItemLocation = InventItemLocation::find(_itemId,inventDimItemLocation.inventDimId); inventDim.InventSiteId = inventDimPurchSetup.InventSiteId; inventDim.InventLocationId = inventDimPurchSetup.InventLocationId; inventDim.wMSLocationId = InventItemLocation.WMSLocationIdDefaultReceipt; inventDim = InventDim::findOrCreate(inventDim); replenishmentOrderLine.InventDimId = inventDim.inventDimId; replenishmentOrderLine.insert(); }
After creating header and lines record for consignment replenishment order, we will post a product receipt using X++ code.
Posting of product receipt for Consignment Replenishment Order
For posting a product receipt of consignment replenishment order we can post a complete product receipt or we can post it partially as well.
We will create a method in this class to post product receipt named as createConsignmentReplenishmentOrderReceipt, this takes ConsignmentReplenishmentOrderHeader record, External product receipt number and External product receipt date as mandatory parameters. If you want to post partial product receipt we have two optional parameters for this as well. Two containers first one to pass on line numbers and second one to pass on quantities to receive of each respective line.
public void createConsignmentReplenishmentOrderReceipt(
ConsignmentReplenishmentOrderHeader _consignmentJournalHeader, TransDate _transDate,
ConsignmentExternalProductReceiptNumber _externalDocumentNumber, container _lineNumbers, container _qtysReceiveNow) { ConsignmentReplenishmentOrderFormLetter consignmentReplenishmentOrderFormLetter; ConsignmentDraftReplenishmentOrderJournalHeader parmTable; ConsignmentDraftReplenishmentOrderJournalLine parmLine; int i; try { consignmentReplenishmentOrderFormLetter = ConsignmentReplenishmentOrderFormLetter::construct(DocumentStatus::PackingSlip); // Setting up the FormLetter framework data. consignmentReplenishmentOrderFormLetter.parmReplenishmentOrderHeader(_consignmentJournalHeader); //Replenishment order header consignmentReplenishmentOrderFormLetter.transDate(_transDate); consignmentReplenishmentOrderFormLetter.printFormLetter(false); consignmentReplenishmentOrderFormLetter.usePrintManagement(false); consignmentReplenishmentOrderFormLetter.printout(Printout::Current); consignmentReplenishmentOrderFormLetter.chooseLines(true); if(conLen(_lineNumbers) >= 1) { for (i = 1; i <= conLen(_lineNumbers); i++) { TradeLineNumber lineNumber = conPeek(_lineNumbers,i); ConsignmentReplenishmentQuantityReceiveNow qtyReceive = conPeek(_qtysReceiveNow,i); select firstonly ReceiveReplenishmentQuantityNow from parmLine where parmLine.ParmId == consignmentReplenishmentOrderFormLetter.parmId() && parmLine.ReplenishmentOrderLineNumber == lineNumber; ConsignmentReplenishmentQuantityReceiveNow actualQty = parmLine.ReceiveReplenishmentQuantityNow; parmLine.clear(); update_recordSet parmLine setting ReceiveReplenishmentQuantityNow = qtyReceive, RemainingInventoryQuantityAfter = actualQty - qtyReceive, RemainingReplenishmentQuantityAfter = actualQty - qtyReceive, ReceiveInventoryQuantityNow = qtyReceive where parmLine.ParmId == consignmentReplenishmentOrderFormLetter.parmId() && parmLine.ReplenishmentOrderLineNumber == lineNumber; } } update_recordSet parmTable setting ExternalDocumentNumber = _externalDocumentNumber where parmTable.ParmId == consignmentReplenishmentOrderFormLetter.parmId(); consignmentReplenishmentOrderFormLetter.runOperation(); } catch (Exception::CLRError) { System.Exception netExcepn = CLRInterop::getLastException(); Info(strFmt('%1', netExcepn.Message)); } }
For looking over the functional process of Creation of consignment replenishment order see the article below.
Thank you for reading this article hope you find it useful.
Technical Consultant
References:
I really enjoy the blog article.Thanks Again. Want more.
I have read some good stuff here. Certainly value bookmarking for revisiting. I wonder how much effort you put to make this sort of great informative web site.
You expressed this superbly. inderal medication
Thanks so much for the blog post.Much thanks again. Really Cool.
Greetings! Very helpful advice within this post! It is the little changes that make the biggest changes. Thanks a lot for sharing!
I quite like reading through an article that will make people think. Also, thank you for allowing for me to comment!
Looking forward to reading more. Great blog post.Thanks Again. Cool.