Skip to main content

Notifications

Announcements

No record found.

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

Create Journal from List of customers

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 
Categories:
  • Maro9595 Profile Picture
    Maro9595 105 on at
    RE: Create Journal from List of customers

    Thank you Mohana

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 on at
    RE: Create Journal from List of customers

    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;

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans