Printing a report for the current document no. in general journal lines

  • Printing a report for the current document no. in general journal lines

    Posted by lulu lemon on May 29, 2026 at 7:57 am

    Hello guys,

    I have a case in Gen. Journal Line (81), page: Fisc. Payment Journal (61122, Worksheet) when clicking an Post and Print button in the ribbon, it posts the current general journal lines and it also generates an Payment report that prints all the posted general journal lines historically ever posted and not just the prints it for the current document no currently posting. Below you can find the code that does this. NOTE: this code acts like standard code and I do not have access to edit it, so whatever I do I need to work on extensions or new files.

    action(“Post and &Print”)

    {

    ApplicationArea = Basic, Suite;

    Caption = ‘Post and &Print’;

    Image = PostPrint;

    Promoted = true;

    PromotedCategory = Category8;

    PromotedIsBig = true;

    ShortCutKey = ‘Shift+F9’;

    ToolTip = ‘Finalize and prepare to print the document or journal. The values and quantities are posted to the related accounts. A report request window where you can specify what to include on the print-out.’;

    trigger OnAction()

    begin

    CODEUNIT.Run(CODEUNIT::”Gen. Jnl.-Post+Print”, Rec);

    CurrentJnlBatchName := GetRangeMax(“Journal Batch Name”);

    SetJobQueueVisibility();

    CurrPage.Update(false);

    end;

    }

    [EventSubscriber(ObjectType::Codeunit, Codeunit::”Batch Posting Print Mgt.”, ‘OnBeforeGLRegPostingReportPrint’, ”, true, true)]

    local procedure “Batch Posting Print Mgt._OnBeforeGLRegPostingReportPrint”(var ReportID: Integer; ReqWindow: Boolean; SystemPrinter: Boolean; var GLRegister: Record “G/L Register”; var Handled: Boolean

    )

    var

    GeneralLedgerEntries: Record “G/L Entry”;

    BankAccountLedgerEntriesAmount: Record “Bank Account Ledger Entry”;

    BankAccountLedgerEntriesAmountNegative: Record “Bank Account Ledger Entry”;

    R1: Report “DTI Payment from Bank”;

    R2: Report “DTI Cash Mandate from Bank”;

    SelectionMngt: Codeunit SelectionFilterManagement;

    RecRef: RecordRef;

    LastDocumentNo: Code[20];

    TotalDocumentNo: Text;

    TotalPostingDate: Text;

    TotalPostingDateDate: Date;

    begin

    Clear(LastDocumentNo);

    Clear(TotalDocumentNo);

    Clear(TotalPostingDate);

    GeneralLedgerEntries.Reset();

    GeneralLedgerEntries.SetFilter(“Entry No.”, ‘%1..%2’, GLRegister.”From Entry No.”, GLRegister.”To Entry No.”);

    GeneralLedgerEntries.SetCurrentKey(“Document No.”);

    GeneralLedgerEntries.Ascending();

    if GeneralLedgerEntries.FindSet() then begin

    Clear(RecRef);

    RecRef.GetTable(GeneralLedgerEntries);

    Evaluate(TotalPostingDateDate, SelectionMngt.GetSelectionFilter(RecRef, GeneralLedgerEntries.FieldNo(“Posting Date”)));

    BankAccountLedgerEntriesAmount.Reset();

    BankAccountLedgerEntriesAmount.SetFilter(“Document No.”, SelectionMngt.GetSelectionFilter(RecRef, GeneralLedgerEntries.FieldNo(“Document No.”)));

    BankAccountLedgerEntriesAmount.SetFilter(“Posting Date”, ‘%1’, TotalPostingDateDate);

    BankAccountLedgerEntriesAmountNegative.Copy(BankAccountLedgerEntriesAmount);

    BankAccountLedgerEntriesAmount.SetFilter(Amount, ‘>%1’, 0);

    if BankAccountLedgerEntriesAmount.FindSet() then begin

    Clear(RecRef);

    RecRef.GetTable(BankAccountLedgerEntriesAmount);

    R1.setDocNoFilter(SelectionMngt.GetSelectionFilter(RecRef, BankAccountLedgerEntriesAmount.FieldNo(“Entry No.”)), ”);

    Report.Print(Report::”R1″, ”);

    end;

    BankAccountLedgerEntriesAmountNegative.Copy(BankAccountLedgerEntriesAmount);

    BankAccountLedgerEntriesAmountNegative.SetFilter(Amount, ‘<%1’, 0);

    if BankAccountLedgerEntriesAmountNegative.FindSet() then begin

    Clear(RecRef);

    RecRef.GetTable(BankAccountLedgerEntriesAmountNegative);

    R2.setDocNoFilter(SelectionMngt.GetSelectionFilter(RecRef, R2.FieldNo(“Entry No.”)), ”);

    Report.Print(Report::”R2 ”);

    end;

    Handled := true;

    end;

    end;

    How do I make it that when clicking the button, to make it possible to print the report first for the current document no. posting and the continue to post the lines. I thought to do it on an event subscriber [EventSubscriber(ObjectType::Codeunit, Codeunit::”Gen. Jnl.-Post+Print”, ‘OnBeforePostJournalBatch’, ”, true, true)] but i am not sure if this is the right approach, any ideas?

    THANK YOU IN ADVANCE šŸ™‚

    Hardik Gupta replied 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • Hardik Gupta

    Member
    June 1, 2026 at 5:09 am
    Up
    0
    Down
    ::

    HI @xhelilianjezwgmail-com

    Good idea. The problem is you’re filtering too much, you’re getting all old documents instead of just the new one you’re posting.

    The good news: you already have what you need. The GLRegister data has only the entries from this posting batch. Just get the document number from there instead of getting all document numbers.

    Something like this:

    </p><p>Get the document number from GLRegister entries</p><p>Filter your report by that one document number</p><p>

    That’s it. Your report will only print the current document, not all the old ones.

    You’re using the right event (OnBeforeGLRegPostingReportPrint), so don’t change it. Just fix the filtering inside.

Log in to reply.

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!