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...
Answered

Create Journal from List of customers

(0) ShareShare
ReportReport
Posted on by 105

Hi All,

I am creating codeunit to create/generate gen journal line(s) if customer has outstanding invoices i used the below code

codeunit 60002 CreateJournal
{
    trigger OnRun()
    begin
        CreateJrn();
    end;

    procedure CreateJrn()
    var
        Cust: Record Customer;
        GenJrnLine: Record "Gen. Journal Line";
    begin

        //Cust.SetFilter("No.", Cust."No.");
        GenJrnLine.SetFilter("Journal Template Name", 'ALLGEMEIN');
        GenJrnLine.SetRange("Journal Batch Name", 'DEFAULT');
        if Cust.FindSet() then begin
            repeat
                if Cust."Outstanding Invoices (LCY)" > 0 then
                    GenJrnLine."Document Type" := GenJrnLine."Document Type"::Invoice;
                GenJrnLine."Account Type" := GenJrnLine."Account Type"::Customer;
                GenJrnLine."Account No." := Cust."No.";
                GenJrnLine.Insert(true)
            until Cust.Next() 0;
            Message('Journal Created');
        end;

    end;
}
but desired outcomes not met, when i tried to execute it keep showing Gen template not found, where am i doing wrong? or any other idea for reaching desired result
thank you 
I have the same question (0)
  • Verified answer
    Mohana Yadav Profile Picture
    61,186 Super User 2026 Season 1 on at

    Outstanding Invoices (LCY) is a flowfield on the customer table so you have to use CALCFIELDS("Outstanding Invoices (LCY)") before using it in code.

    Sample code:

    Cust.SetAutoCalcFields("Outstanding Invoices (LCY)");

           if Cust.FindSet() then begin

               repeat

                   if Cust."Outstanding Invoices (LCY)" > 0 then begin

                       GenJrnLine."Journal Template Name" := 'ALLGEMEIN';

                       GenJrnLine."Journal Batch Name" := 'DEFAULT';

                       GenJrnLine."Line No." := GenJrnLine.GetNewLineNo(GenJrnLine."Journal Template Name", GenJrnLine."Journal Batch Name");

                       GenJrnLine."Document Type" := GenJrnLine."Document Type"::Invoice;

                       GenJrnLine."Account Type" := GenJrnLine."Account Type"::Customer;

                       GenJrnLine."Account No." := Cust."No.";

                       GenJrnLine.Insert(true)

                   end;

               until Cust.Next() = 0;

               Message('Journal Created');

           end;

  • Maro9595 Profile Picture
    105 on at

    Thank you Mohana

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,850 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,045 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans