In this guide, we'll walk through the steps to transfer a custom field from the Sales Line to the General Ledger (G/L) Entry in Dynamics 365 Business Central using AL code. This involves creating table extensions, page extensions, and a codeunit with event subscribers to ensure the custom field is carried through the various stages of the posting process.
tableextension 50113 "Invoice Post. Buffer Ext" extends "Invoice Post. Buffer"
{
fields
{
field(50100; "Mod Fie"; Text[50])
{
Caption = 'Mod Fie';
DataClassification = ToBeClassified;
}
}
}
tableextension 50112 "Gen. Journal Line Ext" extends "Gen. Journal Line"
{
fields
{
field(50100; "Mod Fie"; Text[50])
{
Caption = 'Mod Fie';
DataClassification = ToBeClassified;
}
}
}
tableextension 50111 "G/L Entry Ext" extends "G/L Entry"
{
fields
{
field(50100; "Mod Fie"; Text[50])
{
Caption = 'Mod Fie';
DataClassification = ToBeClassified;
}
}
}
Step 2: Create Page Extensions
pageextension 50116 "Sales Order Subform Ext" extends "Sales Order Subform"
{
layout
{
addafter(Quantity)
{
field("Mod Fie"; Rec."Mod Fie")
{
ApplicationArea = all;
}
}
}
}
pageextension 50115 "Posted Sales Invoice Subform" extends "Posted Sales Invoice Subform"
{
Caption = 'Posted Sales Invoice Subform Ext';
layout
{
addafter(Quantity)
{
field("Mod Fie"; Rec."Mod Fie")
{
ApplicationArea = all;
}
}
}
}
pageextension 50114 "General Ledger Entries Ext" extends "General Ledger Entries"
{
layout
{
addafter("G/L Account No.")
{
field("Mod Fie"; Rec."Mod Fie")
{
ApplicationArea = all;
}
}
}
}
Step 3: Create Codeunit
codeunit 50103 "GL Entry Modify"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnBeforeSalesInvLineInsert', '', true, true)]
local procedure OnBeforeSalesInvLineInsert(var SalesInvLine: Record "Sales Invoice Line"; SalesLine: Record "Sales Line")
begin
SalesInvLine."Mod Fie" := SalesLine."Mod Fie";
end;
[EventSubscriber(ObjectType::Table, Database::"Invoice Post. Buffer", OnAfterInvPostBufferPrepareSales, '', false, false)]
local procedure OnAfterInvPostBufferPrepareSales(var SalesLine: Record "Sales Line"; var InvoicePostBuffer: Record "Invoice Post. Buffer" temporary);
begin
InvoicePostBuffer."Mod Fie" := SalesLine."Mod Fie";
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", OnBeforePostInvPostBuffer, '', false, false)]
local procedure OnBeforePostInvPostBuffer(var GenJnlLine: Record "Gen. Journal Line"; var InvoicePostBuffer: Record "Invoice Post. Buffer" temporary; var SalesHeader: Record "Sales Header"; CommitIsSuppressed: Boolean; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line"; PreviewMode: Boolean);
begin
GenJnlLine."Mod Fie" := InvoicePostBuffer."Mod Fie";
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", OnBeforeInsertGlobalGLEntry, '', false, false)]
local procedure OnBeforeInsertGlobalGLEntry(var GlobalGLEntry: Record "G/L Entry"; GenJournalLine: Record "Gen. Journal Line"; GLRegister: Record "G/L Register");
begin
GlobalGLEntry."Mod Fie" := GenJournalLine."Mod Fie";
end;
}
Thanks for the help but I found the correct answer @
gdrenteria, @
Saurav.Dhyani ,@
YUN ZHU.