In Business Central, there are many scenarios where we may need additional fields from the Sales Header to flow through to the Customer Ledger Entry during invoice or credit memo posting. While it’s possible to achieve this directly, it’s generally better to follow a structured flow:
- Sales Header → Gen. Journal Line
- Gen. Journal Line → Customer Ledger Entry
This approach ensures data consistency and follows Business Central’s standard posting mechanism.
Steps to Implement the Flow
Create Custom Fields
Add the required fields to the following tables:
- Sales Header
- Gen. Journal Line
- Customer Ledger Entry
tableextension 50100 "Sales Header Ext" extends "Sales Header"
{
fields
{
field(50100; "My First Field"; Text[100])
{
DataClassification = ToBeClassified;
Caption = 'My First Field Created';
}
}
}
tableextension 50101 "Posted Sales. Inv. Header Ext" extends 112
{
fields
{
field(50100; "My First Field"; Text[100])
{
DataClassification = ToBeClassified;
Caption = 'My First Field Created';
}
}
}
//Cust. Ledger Entry
tableextension 50102 "Cust. Ledger Entry Ext" extends "Cust. Ledger Entry"
{
fields
{
field(50100; "My First Field"; Text[100])
{
DataClassification = ToBeClassified;
Caption = 'My First Field Created';
}
}
}
//Gen. Journal Line
tableextension 50103 "Gen. Journal Line Ext" extends "Gen. Journal Line"
{
fields
{
field(50100; "My First Field"; Text[100])
{
DataClassification = ToBeClassified;
Caption = 'My First Field Created';
}
}
}
Subscribe to Events
Use event subscribers to handle the data flow:
From Sales Header to Gen. Journal Line during the posting process.
[EventSubscriber(ObjectType::Table, Database::"Gen. Journal Line", 'OnAfterCopyGenJnlLineFromSalesHeader', '', false, false)]
local procedure T81_OnAfterCopyGenJnlLineFromSalesHeader(SalesHeader: Record "Sales Header"; var GenJournalLine: Record "Gen. Journal Line")
begin
GenJournalLine."My First Field" := SalesHeader."My First Field";
end;
From Gen. Journal Line to Customer Ledger Entry during posting.
[EventSubscriber(ObjectType::Table, Database::"Cust. Ledger Entry", 'OnAfterCopyCustLedgerEntryFromGenJnlLine', '', false, false)]
local procedure OnAfterCopyCustLedgerEntryFromGenJnlLine(var CustLedgerEntry: Record "Cust. Ledger Entry"; GenJournalLine: Record "Gen. Journal Line")
begin
CustLedgerEntry."My First Field" := GenJournalLine."My First Field";
end;
Subscribe! so you wont miss latest posts...