Resolving Issue: Project Transactions Not Created After Product Receipt in X++
Introduction
When receiving a product receipt in Microsoft Dynamics 365 Finance and Operations via X++ code, you might encounter a scenario where project transactions are not generated, even when a valid project ID is associated with the purchase order.
Debugging revealed that the system is not calling the runProjectPostings()
method of the PurchFormLetter_PackingSlip
class, which prevents the project packing slip from being posted.
To resolve this, I created the runRemainProjectUpdates
method in the code below.
Code Implementation
Product Receipt Creation
private TestPOReceiptResponseContract createProductReceipt(TestPOReceiptRequestContract _requestContract)
{
PurchFormLetter purchFormLetter;
PurchParmTable purchParmTable;
PurchParmLine purchParmLine;
PurchFormletterParmData purchFormLetterParmData;
TestOrderLineRequestContract orderLineContract = _requestContract.parmOrderLineContract();
PurchTable purchTable = PurchTable::find(orderLineContract.parmPurchaseOrderId());
PurchLine purchLine = PurchLine::find(purchTable.PurchId, orderLineContract.parmLineNumber());
purchFormLetterParmData = PurchFormletterParmData::newData(DocumentStatus::PackingSlip, VersioningUpdateType::Initial);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
PurchParmUpdate purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
purchParmTable.clear();
purchParmTable.TransDate = _requestContract.parmProducReceiptDate();
purchParmTable.Ordering = DocumentStatus::PackingSlip;
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.Num = _requestContract.parmCoupaId();
purchParmTable.PurchId = purchTable.PurchId;
purchParmTable.insert();
purchParmLine.initFromPurchLine(purchLine);
purchParmLine.ReceiveNow = _requestContract.parmTotal();
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.insert();
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.transDate(_requestContract.parmProducReceiptDate());
purchFormLetter.run();
// Generate project item transactions
if (purchTable.ProjId != '')
{
this.runRemainProjectUpdates(purchFormLetter, purchParmTable.ParmId);
}
return this.getResponseContract("@ENG_Labels:ProductReceiptCreated", true);
}
Explicitly Calling runRemainProjectUpdates
to Create Project Transactions
public void runRemainProjectUpdates(PurchFormLetter _purchFormLetter, ParmId _parmId)
{
FormletterOutputContract outputContract = _purchFormLetter.getOutputContract();
VendPackingSlipVersion localVendPackingSlipVersion;
VendPackingSlipJour localVendPackingSlipJour;
VendPackingSlipTrans localVendPackingSlipTrans;
PurchLine localPurchLine;
SalesLine localSalesLine;
SalesFormLetter salesFormLetter;
if (ProjParameters::find().AutomaticItemConsumption == NoYes::Yes)
{
select firstonly RecId, AccountingDate from localVendPackingSlipVersion
where localVendPackingSlipVersion.ParmId == _parmId
exists join localVendPackingSlipJour
where localVendPackingSlipVersion.VendPackingSlipJour == localVendPackingSlipJour.RecId
exists join localVendPackingSlipTrans
where localVendPackingSlipTrans.VendPackingSlipJour == localVendPackingSlipJour.RecId
exists join localPurchLine
where localPurchLine.InventTransId == localVendPackingSlipTrans.InventTransId
&& localPurchLine.ItemRefType == InventRefType::Sales
exists join localSalesLine
where localSalesLine.InventTransId == localPurchLine.InventRefTransId
&& localSalesLine.ProjId;
if (localVendPackingSlipVersion.RecId)
{
salesFormLetter = SalesFormLetter::newFromPurchFormLetter_PackingSlip(
SysOperationHelper::base64Encode(outputContract.parmJournalLinesPacked()),
DocumentStatus::ProjectPackingSlip);
if (localVendPackingSlipVersion.AccountingDate)
{
salesFormLetter.transDate(localVendPackingSlipVersion.AccountingDate);
}
salesFormLetter.runOperation();
}
}
}
No comments:
Post a Comment