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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

I would like to flow the data from Purchase line to GL entry

(3) ShareShare
ReportReport
Posted on by 152
 
this is how I wrote the code to flow the field data from lines to gl.
 
but this is updating only one entry out of 2 gl entries.
I also tried with the unselected event from the screenshot it is also not working.
I searched Purch.-post codeunit for the correct event, which has both parameters i.e: Purchase Line and Gen. Jnl Line, I found few events but those are not working fine.
 
please provide your suggestions.
 
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    100,212 Super User 2026 Season 1 on at
  • Suggested answer
    Yi Yong Profile Picture
    2,704 Super User 2026 Season 1 on at
    Hello,
     
    You will have to transfer from PurchLine -> Invoice Posting Buffer -> Gen. Journal Line -> G/L Entry.
     
  • Gerardo Rentería García Profile Picture
    26,110 Most Valuable Professional on at
  • Suggested answer
    Aman Kakkar Profile Picture
    3,424 Super User 2026 Season 1 on at
    Heya,
     
    You can easily do it using the following sequence of Standard Events for transferring data from Purchase Line to GL Entry for a custom field.
     
    Firstly create the "Custom Field" in the table extensions for Purchase Line, Invoice Posting Buffer, Gen. Journal Line and G/L Entry. Then go ahead with the below mentioned sequence of code.
     
    SEQUENCE: Purchase Line -> Invoice Posting Buffer -> Gen. Journal Line -> G/L Entry.
     
    Below are the events (along with the code) that you can use directly.
     
     
    STEP 01: Purchase Line -> Invoice Posting Buffer
     
    Use 'OnPrepareLineOnAfterFillInvoicePostingBuffer' from Codeunit "Purch. Post Invoice Events".
     
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Post Invoice Events", 'OnPrepareLineOnAfterFillInvoicePostingBuffer', '', false, false)]
        local procedure OnPrepareLineOnAfterFillInvoicePostingBuffer(var InvoicePostingBuffer: Record "Invoice Posting Buffer"; PurchLine: Record "Purchase Line"; var TempInvoicePostingBuffer: Record "Invoice Posting Buffer" temporary; var FALineNo: Integer; var InvDefLineNo: Integer; var DeferralLineNo: Integer; var IsHandled: Boolean)
        begin
            InvoicePostingBuffer."Custom Field" := PurchLine."Custom Field";
        end;
     
    STEP 02: Invoice Posting Buffer -> Gen. Journal Line
     
    Use 'OnPrepareGenJnlLineOnAfterCopyToGenJnlLine' from Codeunit "Purch. Post Invoice Events"
     
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Post Invoice Events", 'OnPrepareGenJnlLineOnAfterCopyToGenJnlLine', '', false, false)]
        local procedure OnPrepareGenJnlLineOnAfterCopyToGenJnlLine(var GenJnlLine: Record "Gen. Journal Line"; PurchHeader: Record "Purchase Header"; InvoicePostingBuffer: Record "Invoice Posting Buffer")
        begin
            GenJnlLine."Custom Field" := InvoicePostingBuffer."Custom Field";
        end;
     
    STEP 03: Gen. Journal Line -> G/L Entry
     
    Use 'OnAfterInitGLEntry' from Codeunit "Gen. Jnl.-Post Line"
     
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnAfterInitGLEntry', '', false, false)]
    
        local procedure OnAfterInitGLEntry(var GLEntry: Record "G/L Entry"; GenJournalLine: Record "Gen. Journal Line"; Amount: Decimal; AddCurrAmount: Decimal; UseAddCurrAmount: Boolean; var CurrencyFactor: Decimal; var GLRegister: Record "G/L Register")
        begin
            GLEntry."Custom Field" := GenJournalLine."Custom Field";
        end;
     
    And that's it. You are done. Please do upvote and move it to Answers if you feel it helped you.
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,012 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 986 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 659 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans