web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Transfer Custom Field from Sales Line to G/L Entry in Business Central?

(3) ShareShare
ReportReport
Posted on by 49
How to Transfer a Custom Field from Sales Line to Sales Invoice Line and Then to General Ledger Entry in Business Central?
 

Hi everyone,

I am working on a customization in Business Central where I need to transfer a custom field value through different stages of a sales transaction. Specifically, I need to:

  1. Transfer the custom field value from the Sales Line to the Sales Invoice Line.
  2. Transfer the custom field value from the Sales Invoice Line to the General Ledger Entry.

I have already extended the necessary tables to include the custom field, but I'm not sure about the events or the best way to ensure the field gets transferred at each step.

I have the same question (0)
  • Suggested answer
    Gerardo Rentería García Profile Picture
    25,213 Most Valuable Professional on at
  • Saurav.Dhyani Profile Picture
    14,380 Super User 2025 Season 2 on at
    Hi,
     
    Sales Line to Sales Invoice Line can happen Directly if field Id is same and field in not a Blob Field? If it's a blob field, you just need to calcfield in Codeunit 80 where Sales Line is transferred to Sales invoice line using transferfields. 
     
    To Move it to General Ledger Entry, Codeunit 80 creates the Journal Lines and From Journal Lines - Item Ledger, Customer Ledger and Value entry is created. From these ledger entries General Ledger Entries are created.
     
    Regards,
    Saurav Dhyani
  • AN-27050650-0 Profile Picture
    49 on at
    Thanks for help @gdrenteria but i was not able to solve the problem as i am not able to get the exact event for my problem. So if you get event please help me.
  • AN-27050650-0 Profile Picture
    49 on at
    Thanks for suggesting the codeunit. I've watched your YouTube videos, but I still can't find the correct event. Can you please help me with exact event? @Saurav.Dhyani
  • Suggested answer
    YUN ZHU Profile Picture
    95,331 Super User 2025 Season 2 on at
    Hi, You can keep track of the standard features below.
    Carry line descriptions to G/L entries when posting
     
    Hope this can give you some hints.
    Thanks.
    ZHU
  • AN-27050650-0 Profile Picture
    49 on at
    Thanks for suggesting the documentation. I've read the documentation, but I still can't find the correct event. Can you please help me with exact event? @YUN ZHU 
  • Verified answer
    AN-27050650-0 Profile Picture
    49 on at

    Solution: Transferring Custom Field from Sales Line to G/L Entry

    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.

    Step 1: Create Table Extensions
     

    tableextension 50109 "Sales Line Ext" extends "Sales Line"
    {
        fields
        {
            field(50150; "Mod Fie"; Text[50])
            {
                Caption = 'Mod Fie';
                DataClassification = ToBeClassified;
            }
        }
    }
    tableextension 50110 "Sales Invoice Line Ext" extends "Sales Invoice Line"
    {
        fields
        {
            field(50100; "Mod Fie"; Text[50])
            {
                Caption = 'Mod Fie';
                DataClassification = ToBeClassified;
            }
        }
    }
    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans