Announcements
No record found.
Can anybody tell me how to cancel a purhase order with purchStatus Open Order and Document status None
in X++
*This post is locked for comments
That means there is nothing confirmed, and you should be able to just delete the PO when you are on the header.
ttsBegin; purchTable = PurchTable::find('yourpurchid', true); purchTable.delete(); ttsCommit;
Hi Faran,
Can you please explain how you want to cancel your PO? using "Deliver remainder function"?
In AX2012, You can close/cancel PO by using Deliver remainder function method described in the link mentioned below:
http://dynamicsteaching.com/how-to-cancel-deliver-remainder-in-ax-2012/
Regards,
Raheel
Hi!
This is a custom class. The class has run(), cancelMarkup() and parmPurchTable() methods.
private void cancelMarkup( TableId _transTableId, RecId _transRecId ) { MarkupTrans markupTrans; while select forupdate * from markupTrans where markupTrans.TransRecId == _transRecId && markupTrans.TransTableId == _transTableId && markupTrans.MarkupCategory == MarkupCategory::Fixed && !markupTrans.IsDeleted { markupTrans.Value = 0; markupTrans.update(); } }
/// <summary> /// Performs the purchase order cancelation. /// </summary> public void run() { PurchLine purchLine; PurchPrepayTable purchPrepayTable; PurchQty purchQty; boolean hasLines = false; boolean messageShown = false; PdsCWInventQty pdsCWQty; // <GBR> boolean clearFiscalDocumentRef_BR = false; NoYes isBrazilEnabled = BrazilParameters::isEnabled(); // </GBR> McrOrderEventTable mcrOrderEventTable; ttsbegin; //selects a prepayment definition which does not have a paid or settled prepayment invoice select firstonly forupdate PrepayApplicationRemaining from purchPrepayTable where purchPrepayTable.PurchTable == purchTable.PurchId && purchPrepayTable.IsDeleted == NoYes::No; if (purchPrepayTable) { if (purchPrepayTable.PrepayApplicationRemaining == 0.0) { //reverses the prepayment invoices which have not been paid or settled PurchPrepayTable::reverseUnpaidPostedAdvances(purchTable.PurchId); purchPrepayTable.Value = 0.0; purchPrepayTable.PrepayLimit = 0.0; purchPrepayTable.PrepayAvailable = 0.0; purchPrepayTable.Description = ''; purchPrepayTable.PrepayCategoryId = 0; purchPrepayTable.update(); } else { //throws error and returns with message that a paid prepayment invoice exists therefore purchase order cannot be cancelled throw error(strFmt("@SYS341265", purchTable.PurchId)); } } if (purchTable.ChangeRequestRequired && purchTable.DocumentState >= VersioningDocumentState::Approved) { if (!purchTable.selectForUpdate()) { purchTable = PurchTable::findRecId(purchTable.RecId, true); } VersioningPurchaseOrder::newPurchaseOrder(purchTable).createChangeRequest(); } else if (!VersioningPurchaseOrder::newPurchaseOrder(purchTable).isLastVersionArchived() && purchTable.DocumentState == VersioningDocumentState::Confirmed) { // force archiving to avoid it during line cancellation as that would lead to update conflicts. purchTable.update(); } // do not cancel invoice matched lines. while select forupdate purchLine where purchLine.PurchId == purchTable.PurchId && purchLine.IsDeleted == NoYes::No { hasLines = true; if (purchLine.IsInvoiceMatched == NoYes::Yes) { if (purchLine.PurchStatus != PurchStatus::Invoiced) { if (!messageShown) { info("@SYS342633"); messageShown = true; } info(strFmt("@SYS342634", purchLine.LineNumber, purchLine.ItemId)); } } else { if (pdsIsCWItem(purchLine.ItemId)) { pdsCWQty = purchLine.pdsCWReceivedInTotal() + purchLine.pdsCWArrived() + purchLine.pdsCWRegistered(); } else { pdsCWQty = 0; } purchQty = purchLine.receivedInTotal() + purchLine.arrivedInPurchUnit() + purchLine.registeredInPurchUnit(); if (purchQty) { // if anything was recieved, arrived or registered then write down to what was recieved, arrived and registered. purchLine.PurchQty = purchQty; purchLine.PdsCWQty = pdsCWQty; purchLine.LineAmount = purchLine.calcLineAmountForced(); } else { purchLine.PurchQty = 0; purchLine.LineAmount = 0; purchLine.PdsCWQty = 0; purchLine.PurchStatus = PurchStatus::Canceled; // <GBR> if (isBrazilEnabled) { clearFiscalDocumentRef_BR = true; } // </GBR> if (purchLine.isDropShipment() && purchTable.InterCompanyDirectDelivery == NoYes::Yes) { purchTable.InterCompanyDirectDelivery = NoYes::No; purchTable.doUpdate(); } } InventMovement::bufferSetTransQtyUnit(purchLine); InventMovement::bufferSetRemainQty(purchLine); // now cancel the markup this.cancelMarkup(purchLine.TableId, purchLine.RecId); purchLine.update(false, true, false); } } // cancel header markup this.cancelMarkup(purchTable.TableId, purchTable.RecId); if (!hasLines) { purchTable.PurchStatus = PurchStatus::Canceled; purchTable.update(); } // <GBR> if (isBrazilEnabled && (clearFiscalDocumentRef_BR || !hasLines)) { purchTable.removeInvoiceRefRecId_BR(); } // </GBR> if ( purchTable.MCRDropShipment ) { mcrOrderEventTable.insertFromDropShipment(purchTable.referenceSalesTable().SalesId, purchTable.PurchId, MCROrderEventType::CancelDropShipPO); } ttscommit; PurchPrepayTable::checkApplicationRemaining(purchTable.PurchId, purchTable.InvoiceAccount); }
Hi,
Try following the link below
daxbeginners.wordpress.com/.../how-to-cancel-deliver-remainder-through-x
Best,
Uday.
Scenario is to change the status to cancel,not to delete the PO,actually i was provided with excel file containing PO's, and i have to change their PurchStatus to "cancel" after verifying that PO has purchStatus "Open Order" and Document status "None".can i do this in job in X++?if yes,suggest me the code.
I suggest the code above.
Scenario is just to change the PurchStatus to "Cancel" after verifying that PO has purchStatus "Open Order" and Document status "None".
I am provided by excel sheet containing 1572 PO's. and i have to run my scenario on that PO's.
If you can help me by solution regarding job in X++ .
Scenario is just to change the PurchStatus to "Cancel",not to delete PO, after verifying that PO has purchStatus "Open Order" and Document status "None".
Create your own class using my suggestion and call it from job inside “while select” statement.
Thanks Rustem Galiamov.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Joris dG 5
Alexey Lekanov 2
Henrik Nordlöf 2 User Group Leader