Hi All,
I had written a method to post product receipt after received external data. The code was running fine for certain product receipt. However on and off, the error below is encountered. Because the change management is activated, hence the error below occured.
Changes to the document are only allowed in state Draft, because change management is activated.
But the issue is not happen on every product receipt, seem only product receipt that have multiple batch number got this error.
Below is the code that use to post product receipt.
public static boolean postProductReceipt(ProductReceiptHeaderInterfaceEntity _prcHeaderInterfaceEntity) { boolean poReceiptPosted; PurchFormLetter purchFormLetter; PurchFormletterParmData purchFormLetterParmData; PurchParmUpdate purchParmUpdate; PurchParmTable purchParmTable; PurchParmLine purchParmLine; PurchTable purchTable; PurchLine purchLine; PurchId purchId; Num packingSlipId; VendPackingSlipJour vendPackingSlipJour; InventTrans inventTrans; InventTransOrigin inventTransOrigin; ProductReceiptLineInterfaceEntity prcLineInterfaceEntity; purchId = _prcHeaderInterfaceEntity.PurchaseOrderNumber; packingSlipId = _prcHeaderInterfaceEntity.ProductReceiptNumber; purchTable = PurchTable::find(purchId); ttsBegin; purchFormLetterParmData = PurchFormletterParmData::newData( DocumentStatus::PackingSlip, VersioningUpdateType::Initial); purchFormLetterParmData.parmOnlyCreateParmUpdate(true); purchFormLetterParmData.createData(false); purchParmUpdate = purchFormLetterParmData.parmParmUpdate(); purchParmTable.clear(); purchParmTable.initValue(); purchParmTable.TransDate = _prcHeaderInterfaceEntity.ProductReceiptDate;//SystemDateGet(); purchParmTable.Ordering = DocumentStatus::PackingSlip; purchParmTable.ParmJobStatus = ParmJobStatus::Waiting; purchParmTable.Num = packingSlipId; 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(); while select purchLine join inventTrans Join inventTransOrigin where purchLine.PurchId == purchTable.purchId && inventTransOrigin.InventTransId == purchLine.InventTransId && inventTrans.InventTransOrigin == inventTransOrigin.RecId && inventTrans.StatusReceipt == StatusReceipt::Registered { purchParmLine.InitFromPurchLine(purchLine); purchParmLine.ReceiveNow = purchline.registeredInPurchUnit(); purchParmLine.setInventReceiveNow(); purchParmLine.ParmId = purchParmTable.ParmId; purchParmLine.TableRefId = purchParmTable.TableRefId; purchParmLine.setQty(DocumentStatus::PackingSlip, false, true); purchParmLine.setLineAmount(); purchParmLine.insert(); } purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip); purchFormLetter.transDate(systemDateGet()); purchFormLetter.proforma(false); purchFormLetter.specQty(PurchUpdate::ReceiveNow); purchFormLetter.purchTable(purchTable); purchFormLetter.parmParmTableNum(purchParmTable.ParmId); purchFormLetter.parmId(purchParmTable.ParmId); purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate()); purchFormLetter.run(); ttsCommit; select firstonly vendPackingSlipJour where vendPackingSlipJour.PurchId == _prcHeaderInterfaceEntity.PurchaseOrderNumber && vendPackingSlipJour.PackingSlipId == _prcHeaderInterfaceEntity.ProductReceiptNumber && vendPackingSlipJour.DeliveryDate == _prcHeaderInterfaceEntity.ProductReceiptDate; if(vendPackingSlipJour) poReceiptPosted = true; else poReceiptPosted = checkFailed('Posting not successful.'); return poReceiptPosted; }
How can I overcome this issue?
Any advice is much appreciated.
Thanks.
Regards,
Teh
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,232 Super User 2024 Season 2
Martin Dráb 230,064 Most Valuable Professional
nmaenpaa 101,156