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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

AUTO INSERT GL LINES

(0) ShareShare
ReportReport
Posted on by 107

Hi All,

I know in General journal batches there is field called Balance account type, and when account is selected it will automatically populates to general journal lines balance account type

pastedimage1677940646010v1.png

Can one please help to know what code unit or triggers which performs that activities because am about adding new field in journal batches and if user use that batch then the values will automatically populate in journal lines

thank you all

  

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,248 Super User 2026 Season 2 on at

    Code is in Table 81 Gen. Journal Line function SetUpNewLine

    You can use event OnAfterSetupNewLine and default custom field

  • Maro9595 Profile Picture
    107 on at

    Thank you for your response Mohana,

    you mean like below? just example

    codeunit 60003 Mypublisher

    {

       [EventSubscriber(ObjectType::Table, Database::"Gen. Journal Line", 'OnBeforeSetUpNewLine', '', false, false)]

       procedure AsignFromBatch(Balance: Decimal; BottomLine: Boolean; LastGenJournalLine: Record "Gen. Journal Line"; var GenJournalBatch: Record "Gen. Journal Batch"; var GenJournalLine: Record "Gen. Journal Line"; var GenJournalTemplate: Record "Gen. Journal Template"; var GLSetupRead: Boolean; var IsHandled: Boolean)

       begin

           if GenJournalBatch."Shortcut Dimension 1 Code" <> '' then

               GenJournalLine."Bal. Gen. Bus. Posting Group" := GenJournalBatch."Shortcut Dimension 1 Code";

       end;

    }

  • Verified answer
    Mohana Yadav Profile Picture
    61,248 Super User 2026 Season 2 on at

    Use same code in OnAfterSetupNewLine instead of OnBeforeSetUpNewLine

  • Maro9595 Profile Picture
    107 on at

    Wow,

    Thank you so much it works

    I was trying to test when user is trying to post with changed dimension in batch

    codeunit 60004 ChecJrnBeforepost

    {

       [EventSubscriber(ObjectType::Codeunit, codeunit::"Gen. Jnl.-Post Batch", 'OnBeforePostGenJnlLine', '', false, false)]

       procedure CheckDim(var GenJournalLine: Record "Gen. Journal Line")

       var

           GenJournalTemplate: Record "Gen. Journal Template";

           GenJournalBatch: Record "Gen. Journal Batch";

       begin

           GenJournalTemplate.Get(GenJournalTemplate.Name);

           GenJournalBatch.Get(GenJournalTemplate.Name, GenJournalBatch.Name);

           GenJournalLine.SetRange("Journal Template Name", GenJournalLine."Journal Template Name");

           GenJournalLine.SetRange("Journal Batch Name", GenJournalLine."Journal Batch Name");

           if GenJournalLine.FindFirst() then begin

               if GenJournalLine."Bal. Gen. Bus. Posting Group" <> GenJournalBatch."Shortcut Dimension 1 Code" then

                   Error('Dimension does not match');

           end;

       end;

  • Mohana Yadav Profile Picture
    61,248 Super User 2026 Season 2 on at

    I appreciate your efforts.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 626 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 425 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 384 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans