Skip to content

[Event Request] codeunit 1323 "Cancel PstdSalesInv (Yes/No)" - procedure "CancelInvoice" #30330

Description

@lapasti

Dear ALAppExtensions Team,

Scenario:
With #29949 (shipped in 28.2), an extension can change what happens to the originating sales order's quantities when a posted invoice is corrected/cancelled (from page actions).
The standard confirmation text before the cancellation becomes inaccurate when that behavior is overridden because it states that the original quantities will be reverted.
Currently there's no event before this specific Confirm call to adjust it (the existing OnCancelInvoiceOnBeforeTestCorrectInvoiceIsAllowed event only gates the validation check, not this message).

Here's the callstack:
UpdateSalesOrderLinesFromCancelledInvoice (\App\Codeunit\1303\Correct Posted Sales Invoice.dal:1120)
OnRun (\App\Codeunit\1303\Correct Posted Sales Invoice.dal:65)
CreateCreditMemo (\App\Codeunit\1303\Correct Posted Sales Invoice.dal:153)
CancelPostedInvoice (\App\Codeunit\1303\Correct Posted Sales Invoice.dal:142)
CancelInvoice (\App\Codeunit\1323\Cancel PstdSalesInv (YesΓüäNo).dal:45)
OnRun (\App\Codeunit\1323\Cancel PstdSalesInv (YesΓüäNo).dal:20)
CancelInvoice - OnAction (\App\Page\143\Posted Sales Invoices.dal:566)

We would like to request the following change:

procedure CancelInvoice(var SalesInvoiceHeader: Record "Sales Invoice Header"): Boolean
    var
        SalesCrMemoHeader: Record "Sales Cr.Memo Header";
        CancelledDocument: Record "Cancelled Document";
        CorrectPostedSalesInvoice: Codeunit "Correct Posted Sales Invoice";
        PageManagement: Codeunit "Page Management";
        IsHandled: Boolean;
        // --> event request
        ConfirmQuestion: Text;
        // <-- event request
    begin
        IsHandled := false;
        OnCancelInvoiceOnBeforeTestCorrectInvoiceIsAllowed(SalesInvoiceHeader, IsHandled);
        if not IsHandled then
            CorrectPostedSalesInvoice.TestCorrectInvoiceIsAllowed(SalesInvoiceHeader, true);
        // --> event request
        ConfirmQuestion := CancelPostedInvoiceQst;
        OnCancelInvoiceOnBeforeConfirm(SalesInvoiceHeader, ConfirmQuestion);
        // <-- event request
        if Confirm(ConfirmQuestion) then
            if CorrectPostedSalesInvoice.CancelPostedInvoice(SalesInvoiceHeader) then
                if Confirm(OpenPostedCreditMemoQst) then begin
                    CancelledDocument.FindSalesCancelledInvoice(SalesInvoiceHeader."No.");
                    SalesCrMemoHeader.Get(CancelledDocument."Cancelled By Doc. No.");
                    IsHandled := false;
                    OnCancelInvoiceOnBeforePostedSalesCreditMemo(SalesCrMemoHeader, IsHandled);
                    if not IsHandled then
                        PageManagement.PageRun(SalesCrMemoHeader);
                    exit(true);
                end;
        exit(false);
    end;

    // --> event request
    [IntegrationEvent(false, false)]
    local procedure OnCancelInvoiceOnBeforeConfirm(var SalesInvoiceHeader: Record "Sales Invoice Header"; var ConfirmQuestion: Text)
    begin
    end;
    // <-- event request

Internal work item: AB#641733

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an event

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions