microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
796 stars 622 forks source link

Add the event OnBeforeCreateCreditMemoOnAction in page "Posted Purchase Invoices" in action "Create Credit Memo" #27329

Open Henriquantos opened 2 months ago

Henriquantos commented 2 months ago

Describe the request

Hi Can you please add the event OnBeforeCreateCreditMemoOnAction in page "Posted Purchase Invoices" similar to the already existing one in "Posted Sales Invoices".

This issue was previously opened by diogoviegas2855 on Issue26714 and it was approved. Nevertheless, the implementation was done on the page "Posted Purchase Invoice" as suggested on Issue26701. The Issue26701 was considered the same as the Issue26714: "This event request is duplicate from https://github.com/microsoft/ALAppExtensions/issues/26714, which is already completed". However, they refer to different pages.

We ask you to add the event to the List page so that the behavior of the Card page can be reproduced. This already happens for the sales so it only makes sense to add this event to the purchases flow.

Actual Code:

action(CreateCreditMemo)
{
    ApplicationArea = Basic, Suite;
    Caption = 'Create Corrective Credit Memo';
    Image = CreateCreditMemo;
    Scope = Repeater;
    ToolTip = 'Create a credit memo for this posted invoice that you complete and post manually to reverse the posted invoice.';

    trigger OnAction()
    var
        PurchaseHeader: Record "Purchase Header";
        CorrectPostedPurchInvoice: Codeunit "Correct Posted Purch. Invoice";
    begin
        if CorrectPostedPurchInvoice.CreateCreditMemoCopyDocument(Rec, PurchaseHeader) then
            PAGE.Run(PAGE::"Purchase Credit Memo", PurchaseHeader);
    end;
}

Suggestion Code:

action(CreateCreditMemo)
{
    ApplicationArea = Basic, Suite;
    Caption = 'Create Corrective Credit Memo';
    Image = CreateCreditMemo;
   Scope = Repeater;
    ToolTip = 'Create a credit memo for this posted invoice that you complete and post manually to reverse the posted invoice.';

    trigger OnAction()
    var
        PurchaseHeader: Record "Purchase Header";
        CorrectPostedPurchInvoice: Codeunit "Correct Posted Purch. Invoice";
        IsHandled: Boolean;
    begin
        IsHandled := false;
        OnBeforeCreateCreditMemoOnAction(Rec, IsHandled);
        if IsHandled then
            exit;

        if CorrectPostedPurchInvoice.CreateCreditMemoCopyDocument(Rec, PurchaseHeader) then begin
            PAGE.Run(PAGE::"Purchase Credit Memo", PurchaseHeader);
            CurrPage.Close();
        end;
    end;
}

[IntegrationEvent(false, false)]
    local procedure OnBeforeCreateCreditMemoOnAction(var PurchInvHeader: Record "Purch. Inv. Header"; var IsHandled: Boolean)
begin
end;

Additional context

I need this event in order to control if i would like to create the standard credit memo or a customized one. Internal work item: AB#539243

nikolakukrika commented 2 months ago

Could you clarify why do you need an event? You could hide the Microsoft action and add your own as you want to override it.

Henriquantos commented 2 months ago

I can, indeed, hide the Microsoft action and add my own to override it.

However, I believe it is only logical to add this event to make the Base Application solution coherent as the event already exists for the remaining pages:

Posted Sales Invoice: image

Posted Sales Invoices: image

Posted Purchase Invoice: image