Skip to main content

Notifications

Business Central forum
Answered

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

Posted on by 39
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.

Categories:
  • Verified answer
    AN-27050650-0 Profile Picture
    AN-27050650-0 39 on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?

    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.
  • AN-27050650-0 Profile Picture
    AN-27050650-0 39 on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?
    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 
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 62,529 Super User on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?
    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
    AN-27050650-0 39 on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?
    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
  • AN-27050650-0 Profile Picture
    AN-27050650-0 39 on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?
    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.
  • Saurav.Dhyani Profile Picture
    Saurav.Dhyani 12,769 User Group Leader on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?
    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
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 4,046 Super User on at
    Transfer Custom Field from Sales Line to G/L Entry in Business Central?

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284,217 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,202 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans