{"title":"Codeunit 1313 Correct Posted Purch. Invoice, extension points 29","url":"https://jonas-paprotka.de/ref/codeunit/1313-correct-posted-purch-invoice/points/","author":"JOP-AL","license":"Metadata from Microsoft's symbol packages. AL source MIT, Copyright (c) Microsoft Corporation. Selection and wording © 2026 JOP-AL. https://jonas-paprotka.de/licenses/","subject":"Microsoft Dynamics 365 Business Central","checked":"2026-11-20","changed":"2026-10-05","object":{"type":"codeunit","id":1313,"name":"Correct Posted Purch. Invoice","app":"Base Application","url":"https://jonas-paprotka.de/ref/codeunit/1313-correct-posted-purch-invoice/"},"major":29,"source":{"url":"https://jonas-paprotka.de/ref/codeunit/1313-correct-posted-purch-invoice/source/","path":"src/Layers/W1/BaseApp/Purchases/History/CorrectPostedPurchInvoice.Codeunit.al","commit":"4303e5e584d3aa5d9e98cbc615525a5396ad6ed7","lines":"a line is <source url>#L<line>"},"steps":{"event":"[line, \"event\", name, handled]: raises an event of this object; handled 1 when it has an IsHandled parameter","call":"[line, \"call\", name, arguments]: calls a procedure of this object","ext":"[line, \"ext\", type, id, name, arguments]: calls a procedure of another object, through a variable declared with that type","write":"[line, \"write\", table id, method, 1 when called with true]: Insert, Modify, ModifyAll, Delete, DeleteAll or Rename","validate":"[line, \"validate\", table id, field name]","run":"[line, \"run\", type, id]: Codeunit.Run, Page.Run, Report.Run and their kin"},"objects":{"codeunit:310":{"name":"No. Series","url":"https://jonas-paprotka.de/ref/codeunit/310-no-series/"},"codeunit:90":{"name":"Purch.-Post","url":"https://jonas-paprotka.de/ref/codeunit/90-purch-post/"},"codeunit:22":{"name":"Item Jnl.-Post Line","url":"https://jonas-paprotka.de/ref/codeunit/22-item-jnl-post-line/"},"codeunit:1313":{"name":"Correct Posted Purch. Invoice","url":"https://jonas-paprotka.de/ref/codeunit/1313-correct-posted-purch-invoice/"},"page:140":{"name":"Posted Purchase Credit Memo","url":"https://jonas-paprotka.de/ref/page/140-posted-purchase-credit-memo/"},"page:52":{"name":"Purchase Credit Memo","url":"https://jonas-paprotka.de/ref/page/52-purchase-credit-memo/"},"table:38":{"name":"Purchase Header","url":"https://jonas-paprotka.de/ref/table/38-purchase-header/"},"codeunit:6620":{"name":"Copy Document Mgt.","url":"https://jonas-paprotka.de/ref/codeunit/6620-copy-document-mgt/"},"table:122":{"name":"Purch. Inv. Header","url":"https://jonas-paprotka.de/ref/table/122-purch-inv-header/"},"page:62":{"name":"Applied Vendor Entries","url":"https://jonas-paprotka.de/ref/page/62-applied-vendor-entries/"},"codeunit:1511":{"name":"Notification Lifecycle Mgt.","url":"https://jonas-paprotka.de/ref/codeunit/1511-notification-lifecycle-mgt/"},"table:1900":{"name":"Cancelled Document","url":"https://jonas-paprotka.de/ref/table/1900-cancelled-document/"},"codeunit:408":{"name":"DimensionManagement","url":"https://jonas-paprotka.de/ref/codeunit/408-dimensionmanagement/"},"table:123":{"name":"Purch. Inv. Line","url":"https://jonas-paprotka.de/ref/table/123-purch-inv-line/"},"table:27":{"name":"Item","url":"https://jonas-paprotka.de/ref/table/27-item/"},"codeunit:11":{"name":"Gen. Jnl.-Check Line","url":"https://jonas-paprotka.de/ref/codeunit/11-gen-jnl-check-line/"},"table:339":{"name":"Item Application Entry","url":"https://jonas-paprotka.de/ref/table/339-item-application-entry/"},"table:32":{"name":"Item Ledger Entry","url":"https://jonas-paprotka.de/ref/table/32-item-ledger-entry/"},"codeunit:5817":{"name":"Undo Posting Management","url":"https://jonas-paprotka.de/ref/codeunit/5817-undo-posting-management/"},"table:39":{"name":"Purchase Line","url":"https://jonas-paprotka.de/ref/table/39-purchase-line/"},"table:312":{"name":"Purchases & Payables Setup","url":"https://jonas-paprotka.de/ref/table/312-purchases-payables-setup/"},"codeunit:5805":{"name":"Item Charge Assgnt. (Purch.)","url":"https://jonas-paprotka.de/ref/codeunit/5805-item-charge-assgnt-purch/"},"table:125":{"name":"Purch. Cr. Memo Line","url":"https://jonas-paprotka.de/ref/table/125-purch-cr-memo-line/"},"table:4":{"name":"Currency","url":"https://jonas-paprotka.de/ref/table/4-currency/"},"table:330":{"name":"Currency Exchange Rate","url":"https://jonas-paprotka.de/ref/table/330-currency-exchange-rate/"},"table:5765":{"name":"Warehouse Request","url":"https://jonas-paprotka.de/ref/table/5765-warehouse-request/"},"table:130":{"name":"Incoming Document","url":"https://jonas-paprotka.de/ref/table/130-incoming-document/"},"table:133":{"name":"Incoming Document Attachment","url":"https://jonas-paprotka.de/ref/table/133-incoming-document-attachment/"}},"procs":[{"name":"OnRun","line":35,"kind":"trigger","steps":[[42,"call","UnapplyCostApplication",2],[43,"event","OnRunOnBeforeCreateCopyDocument",0],[44,"call","CreateCopyDocument",4],[47,"call","CheckPurchaseOrderLinesCanAbsorbCancellation",1],[49,"ext","codeunit",310,"IsNoSeriesInDateOrder",1],[51,"event","OnAfterCreateCorrectivePurchCrMemo",0],[55,"run","codeunit",90],[56,"call","SetTrackInfoForCancellation",1],[58,"ext","codeunit",22,"RedoApplications",0],[59,"call","UpdatePurchaseOrderLinesFromCancelledInvoice",1],[60,"call","ResetIncomingDocumentForCancelledInvoice",1],[61,"event","OnRunOnAfterUpdatePurchaseOrderLinesFromCancelledInvoice",0]]},{"name":"CancelPostedInvoice","line":126,"kind":"procedure","params":1,"steps":[[129,"call","CreateCreditMemo",1]]},{"name":"CreateCreditMemo","line":132,"kind":"procedure","access":"local","params":1,"steps":[[138,"call","TestCorrectInvoiceIsAllowed",2],[139,"run","codeunit",1313],[144,"event","OnBeforeShowPostedPurchCreditMemo",1],[146,"run","page",140],[152,"event","OnCreateCreditMemoOnBeforeConfirmPostingCreditMemoFailedOpen",1],[155,"event","OnBeforeShowPurchaseCreditMemo",1],[157,"run","page",52]]},{"name":"CreateCopyDocument","line":167,"kind":"procedure","access":"local","params":4,"steps":[[171,"event","OnBeforeCreateCopyDocument",0],[175,"ext","table",38,"SetAllowSelectNoSeries",0],[176,"event","OnBeforePurchaseHeaderInsert",0],[177,"write",38,"Insert",1],[181,"ext","codeunit",6620,"SetPropertiesForCorrectiveCreditMemo",1],[183,"ext","codeunit",6620,"SetPropertiesForInvoiceCorrection",1],[188,"ext","codeunit",6620,"CopyPurchaseDocForInvoiceCancelling",2],[190,"event","OnAfterCreateCopyDocument",0]]},{"name":"CreateCreditMemoCopyDocument","line":193,"kind":"procedure","params":2,"steps":[[197,"ext","table",122,"IsFullyOpen",0],[198,"call","ShowInvoiceAppliedNotification",1],[207,"call","CreateCopyDocument",4]]},{"name":"CreateCorrectiveCreditMemo","line":211,"kind":"procedure","params":1,"steps":[[220,"call","CreateCopyDocument",4],[222,"event","OnBeforeShowPurchaseCreditMemo",1],[224,"run","page",52]]},{"name":"ShowAppliedEntries","line":227,"kind":"procedure","params":1,"steps":[[234,"run","page",62]]},{"name":"CancelPostedInvoiceStartNewInvoice","line":242,"kind":"procedure","params":2,"steps":[[246,"call","CreateCreditMemo",1],[247,"call","CreateCopyDocument",4],[248,"event","OnCancelPostedInvoiceStartNewInvoiceOnAfterCreateCorrPurchaseInvoice",0]]},{"name":"TestCorrectInvoiceIsAllowed","line":253,"kind":"procedure","params":2,"steps":[[256,"call","TestIfPostingIsAllowed",1],[257,"call","TestIfInvoiceIsCorrectedOnce",1],[258,"call","TestIfInvoiceIsNotCorrectiveDoc",1],[259,"call","TestIfInvoiceIsPaid",1],[260,"call","TestIfVendorIsBlocked",2],[261,"call","TestIfVendorIsBlocked",2],[262,"call","TestVendorDimension",2],[263,"call","TestDimensionOnHeader",1],[264,"call","TestPurchaseLines",1],[265,"call","TestIfAnyFreeNumberSeries",1],[266,"call","TestExternalDocument",1],[267,"call","TestInventoryPostingClosed",1],[269,"event","OnAfterTestCorrectInvoiceIsAllowed",0]]},{"name":"ShowInvoiceAppliedNotification","line":272,"kind":"procedure","access":"local","params":1,"steps":[[290,"ext","codeunit",1511,"SendNotification",2]]},{"name":"SetTrackInfoForCancellation","line":293,"kind":"procedure","access":"local","params":1,"steps":[[300,"event","OnBeforeSetTrackInfoForCancellation",1],[306,"ext","table",1900,"InsertPurchInvToCrMemoCancelledDocument",2]]},{"name":"TestDimensionOnHeader","line":309,"kind":"procedure","access":"local","params":1,"steps":[[313,"ext","codeunit",408,"CheckDimIDComb",1],[314,"call","ErrorHelperHeader",2]]},{"name":"TestIfVendorIsBlocked","line":317,"kind":"procedure","access":"local","params":2,"steps":[[323,"call","ErrorHelperHeader",2]]},{"name":"TestVendorDimension","line":326,"kind":"procedure","access":"local","params":2,"steps":[[336,"ext","codeunit",408,"CheckDimValuePosting",3],[337,"call","ErrorHelperAccount",5]]},{"name":"TestPurchaseLines","line":340,"kind":"procedure","access":"local","params":1,"steps":[[355,"call","IsCommentLine",1],[356,"ext","table",123,"IsCancellationSupported",0],[356,"call","NotInvRndAccount",2],[357,"call","ErrorHelperLine",2],[362,"ext","table",27,"IsInventoriableType",0],[363,"call","WasNotCancelled",1],[364,"ext","table",123,"CalcReceivedPurchNotReturned",3],[366,"event","OnTestPurchaseLinesOnAfterCalcThrowItemReturnedError",0],[368,"call","ErrorHelperLine",2],[372,"call","ErrorHelperLine",2],[376,"call","ErrorHelperLine",2],[381,"ext","codeunit",408,"CheckDimValuePosting",3],[382,"call","ErrorHelperAccount",5],[384,"ext","table",27,"IsInventoriableType",0],[385,"call","TestInventoryPostingSetup",1],[388,"call","TestGenPostingSetup",1],[389,"call","TestVendorPostingGroup",1],[390,"call","TestVATPostingSetup",1],[392,"ext","codeunit",408,"CheckDimIDComb",1],[393,"call","ErrorHelperLine",2]]},{"name":"TestGLAccount","line":398,"kind":"procedure","access":"local","params":2,"steps":[[408,"call","ErrorHelperAccount",5],[414,"ext","codeunit",408,"CheckDimValuePosting",3],[415,"call","ErrorHelperAccount",5]]},{"name":"TestGLAccount","line":419,"kind":"procedure","access":"local","params":2,"steps":[[429,"call","ErrorHelperAccount",5],[433,"ext","codeunit",408,"CheckDimValuePosting",3],[434,"call","ErrorHelperAccount",5]]},{"name":"TestIfInvoiceIsPaid","line":439,"kind":"procedure","access":"local","params":1,"steps":[[444,"event","OnBeforeTestIfInvoiceIsPaid",1],[451,"call","ErrorHelperHeader",2]]},{"name":"TestIfInvoiceIsCorrectedOnce","line":454,"kind":"procedure","access":"local","params":1,"steps":[[458,"ext","table",1900,"FindPurchCancelledInvoice",1],[459,"call","ErrorHelperHeader",2]]},{"name":"TestIfInvoiceIsNotCorrectiveDoc","line":462,"kind":"procedure","access":"local","params":1,"steps":[[466,"ext","table",1900,"FindPurchCorrectiveInvoice",1],[467,"call","ErrorHelperHeader",2]]},{"name":"TestIfPostingIsAllowed","line":470,"kind":"procedure","access":"local","params":1,"steps":[[474,"ext","codeunit",11,"DateNotAllowed",1],[475,"call","ErrorHelperHeader",2]]},{"name":"TestIfAnyFreeNumberSeries","line":478,"kind":"procedure","access":"local","params":1,"steps":[[488,"event","OnBeforeTestIfAnyFreeNumberSeries",1],[495,"call","TryPeekNextNo",2],[496,"call","ErrorHelperHeader",2],[504,"call","TryPeekNextNo",2],[505,"call","ErrorHelperHeader",2],[507,"call","TryPeekNextNo",2],[508,"call","ErrorHelperHeader",2]]},{"name":"TryPeekNextNo","line":512,"kind":"procedure","access":"local","params":2,"steps":[[516,"ext","codeunit",310,"PeekNextNo",2]]},{"name":"TestExternalDocument","line":520,"kind":"procedure","access":"local","params":1,"steps":[[526,"call","ErrorHelperHeader",2]]},{"name":"TestInventoryPostingClosed","line":529,"kind":"procedure","access":"local","params":1,"steps":[[544,"call","ErrorHelperHeader",2]]},{"name":"TestGenPostingSetup","line":548,"kind":"procedure","access":"local","params":1,"steps":[[558,"call","TestGLAccount",2],[560,"call","TestGLAccount",2],[562,"call","IsCheckDirectCostAppliedAccount",1],[564,"call","TestGLAccount",2],[566,"call","HasLineDiscountSetup",1],[568,"call","TestGLAccount",2]]},{"name":"TestVendorPostingGroup","line":571,"kind":"procedure","access":"local","params":1,"steps":[[577,"call","TestGLAccount",2]]},{"name":"TestVATPostingSetup","line":580,"kind":"procedure","access":"local","params":1,"steps":[[586,"event","OnBeforeTestVATPostingSetup",1],[593,"call","TestGLAccount",2]]},{"name":"TestInventoryPostingSetup","line":597,"kind":"procedure","access":"local","params":1,"steps":[[603,"event","OnBeforeTestInventoryPostingSetup",1],[609,"call","TestGLAccount",2]]},{"name":"IsCommentLine","line":612,"kind":"procedure","access":"local","params":1,"steps":[[615,"event","OnAfterIsCommentLine",0]]},{"name":"UnapplyCostApplication","line":638,"kind":"procedure","access":"local","params":2,"steps":[[645,"event","OnBeforeUnAppyCostApplication",1],[649,"call","FindItemLedgEntries",2],[650,"call","FindAppliedInbndEntries",2],[652,"ext","codeunit",22,"UnApply",1]]},{"name":"FindItemLedgEntries","line":658,"kind":"procedure","params":2,"steps":[[666,"ext","table",123,"GetItemLedgEntries",2]]},{"name":"FindAppliedInbndEntries","line":670,"kind":"procedure","access":"local","params":2,"steps":[[675,"write",339,"DeleteAll"],[678,"ext","table",339,"AppliedOutbndEntryExists",3],[682,"write",339,"Insert"]]},{"name":"UpdatePurchaseOrderLinesFromCancelledInvoice","line":832,"kind":"procedure","access":"local","params":1,"steps":[[844,"write",32,"DeleteAll"],[845,"ext","table",123,"GetItemLedgEntries",2],[847,"call","UpdatePurchaseOrderLineInvoicedQuantity",3],[848,"call","UpdatePurchaseOrderLinePrepmtAmount",1],[849,"call","UpdateReverseItemChargeAssignment",2],[851,"ext","codeunit",5817,"RevertPostedItemTracking",3]]},{"name":"UpdatePurchaseOrderLineInvoicedQuantity","line":856,"kind":"procedure","access":"local","params":3,"steps":[[861,"event","OnBeforeUpdatePurchaseOrderLineInvoicedQuantity",1],[869,"ext","table",39,"InitOutstanding",0],[870,"ext","table",39,"InitQtyToReceive",0],[871,"ext","table",39,"InitQtyToInvoice",0],[872,"write",39,"Modify"]]},{"name":"HasLineDiscountSetup","line":875,"kind":"procedure","access":"local","params":1,"steps":[[877,"ext","table",312,"GetRecordOnce",0],[881,"event","OnHasLineDiscountSetup",0]]},{"name":"IsCheckDirectCostAppliedAccount","line":884,"kind":"procedure","access":"local","params":1,"steps":[[891,"ext","table",27,"IsInventoriableType",0],[893,"event","OnAfterIsCheckDirectCostAppliedAccount",0]]},{"name":"UpdateReverseItemChargeAssignment","line":896,"kind":"procedure","access":"local","params":2,"steps":[[910,"ext","codeunit",5805,"ReverseItemChargeAssgnt",2]]},{"name":"UpdatePurchaseOrderLineIfExist","line":913,"kind":"procedure","access":"internal","params":1,"steps":[[923,"call","GetPurchInvLineAndUpdatePurchaseOrderLines",1]]},{"name":"GetPurchInvLineAndUpdatePurchaseOrderLines","line":927,"kind":"procedure","access":"local","params":1,"steps":[[931,"ext","table",125,"GetPurchaseInvoiceLine",1],[933,"call","UpdatePurchaseOrderLinesFromCreditMemo",2]]},{"name":"UpdatePurchaseOrderLinesFromCreditMemo","line":936,"kind":"procedure","access":"local","params":2,"steps":[[946,"ext","table",123,"GetItemLedgEntries",2],[948,"call","UpdatePurchaseOrderLineInvoicedQuantity",3],[949,"call","UpdatePurchaseOrderLinePrepmtAmount",1],[953,"call","UpdateWhseRequest",4],[956,"ext","codeunit",5817,"RevertPostedItemTracking",3]]},{"name":"UpdatePurchaseOrderLinePrepmtAmount","line":960,"kind":"procedure","access":"local","params":1,"steps":[[977,"ext","table",4,"Initialize",2],[980,"call","ValidatePrepmtAmountsWithCurrency",4],[982,"call","ValidatePrepmtAmountsFromPurchInv",3],[984,"validate",39,"Prepmt Amt Deducted"],[991,"validate",39,"Prepmt Amt to Deduct"],[998,"write",39,"Modify",1]]},{"name":"ValidatePrepmtAmountsWithCurrency","line":1001,"kind":"procedure","access":"local","params":4,"steps":[[1005,"validate",39,"Prepmt. Amount Inv. (LCY)"],[1009,"ext","table",330,"ExchangeAmtFCYToLCY",4],[1018,"validate",39,"Prepmt. VAT Amount Inv. (LCY)"],[1022,"ext","table",330,"ExchangeAmtFCYToLCY",4]]},{"name":"ValidatePrepmtAmountsFromPurchInv","line":1032,"kind":"procedure","access":"local","params":3,"steps":[[1034,"validate",39,"Prepmt. Amount Inv. (LCY)"],[1041,"validate",39,"Prepmt. VAT Amount Inv. (LCY)"]]},{"name":"UpdateWhseRequest","line":1049,"kind":"procedure","access":"local","params":4,"steps":[[1054,"ext","table",5765,"SetSourceFilter",3],[1058,"write",5765,"Modify"]]},{"name":"ResetIncomingDocumentForCancelledInvoice","line":1062,"kind":"procedure","access":"local","params":1,"steps":[[1096,"write",130,"Modify",1],[1099,"write",133,"ModifyAll"],[1100,"write",133,"ModifyAll"]]},{"name":"CheckPurchaseOrderLinesCanAbsorbCancellation","line":1103,"kind":"procedure","access":"local","params":1,"steps":[[1115,"call","CheckCancelledQuantityWithinOrderLine",3]]}]}