How to Post Partial Product Receipt in D365FO Using X++ Code
Handling partial product receipts in Microsoft Dynamics 365 for Finance and Operations (D365FO) can be crucial for businesses that receive shipments in stages. In this blog, we'll explore how to post a partial product receipt using X++ code. We'll refer to a specific code example to guide us through the process.
Introduction
Partial product receipt refers to the process of receiving a portion of the goods ordered rather than the entire quantity. This is common in scenarios where suppliers deliver products in multiple shipments. Posting partial product receipts accurately in D365FO ensures that inventory records reflect the actual quantities received.
Code Example Overview
Here's an example of X++ code that demonstrates how to post a partial product receipt. This example focuses on receiving a specific quantity of a purchase order line.
internal final class POReceiptJobTest
{
///
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
///
/// The specified arguments.
public static void main(Args _args)
{
PurchTable purchTable;
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmTable purchParmTable;
PurchLine purchLine;
PurchParmLine purchParmLine;
ttsBegin;
// Find the purchase order
purchTable = PurchTable::find('000039');
// Create PurchParamUpdate table
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PackingSlip,
VersioningUpdateType::Initial);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
PurchParmUpdate purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
// Set PurchParmTable table
purchParmTable.clear();
purchParmTable.TransDate = SystemDateGet();
purchParmTable.Ordering = DocumentStatus::PackingSlip;
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.Num = 'Test234567'; // PR
purchParmTable.PurchId = purchTable.PurchId;
purchParmTable.PurchName = purchTable.PurchName;
purchParmTable.DeliveryName = purchTable.DeliveryName;
purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress;
purchParmTable.OrderAccount = purchTable.OrderAccount;
purchParmTable.CurrencyCode = purchTable.CurrencyCode;
purchParmTable.InvoiceAccount = purchTable.InvoiceAccount;
purchParmTable.ParmId = purchParmUpdate.ParmId;
purchParmTable.insert();
// Set PurchParmLine table
select purchLine
where purchLine.PurchId == purchTable.PurchId &&
purchLine.LineNumber == 1;
purchParmLine.initFromPurchLine(purchLine);
purchParmLine.ReceiveNow = 5; // Partial quantity received
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
purchParmLine.setLineAmount();
purchParmLine.insert();
// Post the packing slip
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::All);
purchFormLetter.purchTable(purchTable);
purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.run();
ttsCommit;
}
}
If you have any questions or need further assistance, feel free to leave a comment below!
No comments:
Post a Comment