Dynamics 365 Business Central: Set External Document No./Vendor Invoice No. as mandatory (Ext. Doc. No. Mandatory)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about a simple topic, how to set External Document No./Vendor Invoice No. as mandatory in Business Central.
You can enter external document numbers for customers and vendors in all sales and purchase orders, invoices, and credit memos. For example,
On the Sales Order: External Document No.

On the Purchase Order: Vendor Invoice No. (With a red asterisk)

You can use these numbers to search for posted sales and purchase lines later. I have been asked several times why the Vendor Invoice No. on the Purchase Order is required in the standard test database, but the External Document No. is not. Let’s look at a simple example,

You need to enter the document number of the document from the vendor in the Vendor Invoice No. field, so that this document stays linked to the original.

This is actually very simple, there is a setting in both Sales & Receivables Setup and Purchases & Payables Setup.
Sales & Receivables Setup: Not enabled by default

Ext. Doc. No. Mandatory
Specifies if it is mandatory to enter an external document number in the External Document No. field on a sales header or the External Document No. field on a general journal line.

Purchases & Payables Setup: Enabled by default

Ext. Doc. No. Mandatory
Specifies if it is mandatory to enter an external document number in the External Document No. field on a purchase header or the External Document No. field on a general journal line.

If you enable this setting in Sales & Receivables Setup, you can see a red asterisk in front of the External Document No., just like in Purchase Order.

This field is checked for any value when posting invoice.

The error message on the Purchase Order is more user-friendly……

External Document No. must have a value in Sales Header: Document Type=Order, No.=101013. It cannot be zero or empty.

PS: Dynamics 365 Business Central: The red asterisk next to a field (mandatory field???)

This will also affect the General Journal.

So if you post an invoice through the General Journal, please add this field to the page first. It is hidden by default.

It is also important to note that Business Central does not check if these external document numbers are unique or duplicates. So this requires some simple customization if you need this control. For example,

Or

Test code: (Please note that the source code is for reference only, you can improve it according to your own needs)

tableextension 50112 PurchaseHeaderExt extends "Purchase Header"
{
    fields
    {
        modify("Vendor Invoice No.")
        {
            trigger OnBeforeValidate()
            var
                PurchaseHeader: Record "Purchase Header";
                PurchaseInvHeader: Record "Purch. Inv. Header";
            begin
                if Rec."Vendor Invoice No." <> '' then begin
                    PurchaseHeader.Reset();
                    PurchaseHeader.SetRange("Vendor Invoice No.", Rec."Vendor Invoice No.");
                    if PurchaseHeader.FindSet() then
                        Error('Vendor Invoice No. already exists. Please check Purchase Order %1.', PurchaseHeader."No.");
                    PurchaseInvHeader.Reset();
                    PurchaseInvHeader.SetRange("Vendor Invoice No.", Rec."Vendor Invoice No.");
                    if PurchaseInvHeader.FindSet() then
                        Error('Vendor Invoice No. already exists. Please check Posted Purchase Invoice %1.', PurchaseInvHeader."No.");
                end;
            end;
        }
    }
}

Very simple, give it a try!!!😁

PS: External document numbers and Enter external document numbers

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL