Dynamics 365 Business Central: How to extend the Posted Document Update page (A solution for editing Posted Document)

Dynamics 365 Business Central

Hi, Readers.
Sometimes you have to update a posted document because information that is relevant to the document has changed. On a posted sales document, this can be the shipping agent’s package tracking number, for example. On a posted purchase document, this can be a payment reference text.

To solve this problem, Microsoft has prepared some “Update” pages for us.
For example, Posted Purch. Invoice – Update (1351, Card)

You perform the change on an editable version of the original document, indicated by “– Update” in the page title. The page contains a subset of the fields on the original document, of which some are non-editable fields that are shown for information only.

https://docs.microsoft.com/en-US/dynamics365/business-central/across-edit-posted-document

Let’s see more details.

Choose the Tell Me icon, enter Posted Purchase Invoices, and then choose the related link.

Select the document that you want to edit, and then choose the Update Document action.

Alternatively, open the document and then choose the action.

On the Posted Purch. Invoice – Update page, edit the Payment Method Code field, for example.

Then Choose OK.

The posted purchase invoice is updated.

The steps are similar for the other supported documents. But, that’s not the main thing I want to discuss in this post, as Microsoft provided very few fields (due to security), is it possible to extend this Update page? And how to do it?

Let me assume a scenario where the Payment Terms Code and Shipment Method Code need to be added to the Update page and can be edited.

This requires three steps.

1. Add the fields to the Update page.

2. Tell Business Central that there is a data changed.

Standard Codes:

PS: Different documents have different ‘OnAfterRecordChanged‘ events.

3. Update data.

Standard Codes:

Test Video:

Source Code:

pageextension 50111 PostedPurchInvoiceUpdateExt extends "Posted Purch. Invoice - Update"
{
    layout
    {
        addafter("Payment Method Code")
        {
            field("Payment Terms Code"; Rec."Payment Terms Code")
            {
                ApplicationArea = All;
            }
            field("Shipment Method Code"; Rec."Shipment Method Code")
            {
                ApplicationArea = All;
            }
        }
    }
}

codeunit 50111 EditPostedDocumentsHandler
{
    [EventSubscriber(ObjectType::Page, Page::"Posted Purch. Invoice - Update", 'OnAfterRecordChanged', '', false, false)]
    local procedure OnAfterRecordChanged(var PurchInvHeader: Record "Purch. Inv. Header"; xPurchInvHeader: Record "Purch. Inv. Header"; var IsChanged: Boolean; xPurchInvHeaderGlobal: Record "Purch. Inv. Header");
    begin
        IsChanged := (PurchInvHeader."Payment Terms Code" <> xPurchInvHeaderGlobal."Payment Terms Code") or
                    (PurchInvHeader."Shipment Method Code" <> xPurchInvHeaderGlobal."Shipment Method Code");
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Inv. Header - Edit", 'OnBeforePurchInvHeaderModify', '', false, false)]
    local procedure OnBeforePurchInvHeaderModify(var PurchInvHeader: Record "Purch. Inv. Header"; PurchInvHeaderRec: Record "Purch. Inv. Header");
    begin
        PurchInvHeader."Payment Terms Code" := PurchInvHeaderRec."Payment Terms Code";
        PurchInvHeader."Shipment Method Code" := PurchInvHeaderRec."Shipment Method Code";
    end; 
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました