Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

AUTO INSERT GL LINES

Posted on by 105

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

  

  • Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: AUTO INSERT GL LINES

    I appreciate your efforts.

  • Maro9595 Profile Picture
    Maro9595 105 on at
    RE: AUTO INSERT GL LINES

    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;

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: AUTO INSERT GL LINES

    Use same code in OnAfterSetupNewLine instead of OnBeforeSetUpNewLine

  • Maro9595 Profile Picture
    Maro9595 105 on at
    RE: AUTO INSERT GL LINES

    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;

    }

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: AUTO INSERT GL LINES

    Code is in Table 81 Gen. Journal Line function SetUpNewLine

    You can use event OnAfterSetupNewLine and default custom field

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans