Hi, Readers.
Yesterday, I saw an interesting question in Business Central forum, Order No./Order Line No. is not populated when using the Get Receipt Lines action in Purchase Invoice, More details: Order No not populated when using the Get Receipt Lines action in Purchase Invoices.
Let’s see more details.
As you might know, if you want to invoice more than one purchase receipt at a time, you can select multiple receipt lines on the purchase invoice.
Before you can create a combined purchase receipt, more than one receipt from the same vendor in the same currency must be posted. In other words, you must have filled in two or more purchase orders and posted them as received, but not invoiced.


Then create a new purchase invoice for the vendor, on the Lines FastTab, choose the Get Receipt Lines action.

You can select multiple receipt lines that you want to include in the invoice.

But there’s a small problem. When selecting a receipt line, the Order No./Order Line No. is not automatically populated to the Purchase Line on the Purch. Invoice Subform (55, ListPart). For example,


In the receipt line, you can find the Order No./Order Line No.
Order No.: 106016
Order Line No.: 10000

But after adding it to the Purchase Invoice, both Order No. and Order Line No. are empty.

This is standard behavior, and there was an idea in August 2021, Show purchase order no. on ALL posted purchase invoices. The Business Central Team said it had been added to the roadmap, but unfortunately, as of the current BC25.3 version, this feature has not been added.

So we need to do some small customization. It’s not difficult.
PS: To facilitate testing, I first added these two fields to the page.
More details: Business Central 2023 wave 2 (BC23): Add existing table fields to optimize your pages (Adding Table Fields to Page without Page Extensions)


First let’s look at the standard code, and find out which event we can subscribe to. (You can skip this step if you just want to see the results)
page 55 “Purch. Invoice Subform”:


codeunit 74 “Purch.-Get Receipt”:

page 5709 “Get Receipt Lines”:


codeunit 74 “Purch.-Get Receipt”:

Found it, we can use the following event.
OnAfterInsertInvoiceLineFromReceiptLine(PurchRcptLine, PurchLine, PurchRcptLine2, TransferLine);

Let’s look at a simple example. First we can add a setting in Purchases & Payables Setup to control this behavior.


Then add the logic needed this time.

Great.

The values of these two fields will also be transferred to the Posted Purchase Invoice Lines after posting.



Test video:
Give it a try!!!😁
Source Code: GitHub (Please note that the source code is for reference only, you can improve it according to your own needs)
tableextension 50100 PurchasesPayablesSetupExt extends "Purchases & Payables Setup"
{
fields
{
field(50200; "Copy Order No. to Invoice"; Boolean)
{
Caption = 'Copy Order No. to Invoice';
ToolTip = 'When enabled, the Order No. and Order Line No. fields will be copied from the Purchase Order to the Purchase Invoice when using the Get Receipt Lines action in Purchase Invoices.';
}
}
}
pageextension 50100 PurchasesPayablesSetupExt extends "Purchases & Payables Setup"
{
layout
{
addbefore("Prepmt. Auto Update Frequency")
{
field("Copy Order No. to Invoice"; Rec."Copy Order No. to Invoice")
{
ApplicationArea = All;
}
}
}
}
codeunit 50112 EventHandler
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Get Receipt", OnAfterInsertInvoiceLineFromReceiptLine, '', false, false)]
local procedure PurchGetReceiptOnAfterInsertInvoiceLineFromReceiptLine(var PurchRcptLine: Record "Purch. Rcpt. Line"; var PurchLine: Record "Purchase Line")
var
PurchPayablesSetup: Record "Purchases & Payables Setup";
begin
if PurchPayablesSetup.Get() then
if PurchPayablesSetup."Copy Order No. to Invoice" then begin
PurchLine."Order No." := PurchRcptLine."Order No.";
PurchLine."Order Line No." := PurchRcptLine."Order Line No.";
PurchLine.Modify(true);
end;
end;
}
END
Hope this will help.
Thanks for reading.
ZHU
コメント