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

Community site session details

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

Custom Journal Posting Issue in Business Central: No. Series Gaps and Reappearing Entries

(4) ShareShare
ReportReport
Posted on by 8
Microsoft Dynamics 365 Business Central allows developers to automate financial processes using AL code. However, while customizing journal posting, I recently faced a tricky issue related to No. Series and General journal line reappearance.
My Scenario
I was developing a custom Commission Posting process to automatically create and post General Journal Lines under:
Template Name: GENERAL
Batch Name: COMMISSION
The No. Series used does not allow gaps, ensuring continuous document numbering.
Here’s the key part of the implementation:

local procedure CreateCommissionGLEntry2()
var
    JournalLine: Record "Gen. Journal Line";
    GenJnlBatch: Record "Gen. Journal Batch";
    NoSeriesMgt: Codeunit "No. Series";
    GenJnlPost: Codeunit "Gen. Jnl.-Post";
    PeekNo, NextDocumentNo: Code[20];
begin
    GenJnlBatch.SetRange("Journal Template Name", 'GENERAL');
    GenJnlBatch.SetRange("Name", 'COMMISSION');
    GenJnlBatch.FindFirst();
    PeekNo := NoSeriesMgt.PeekNextNo(GenJnlBatch."No. Series", WorkDate());
    DeleteEarlierUnpostedGenJournalDocs('GENERAL', 'COMMISSION', PeekNo);
    NextDocumentNo := NoSeriesMgt.GetNextNo(GenJnlBatch."No. Series", WorkDate(), false);
    JournalLine.Init();
    JournalLine.Validate("Journal Template Name", 'GENERAL');
    JournalLine.Validate("Journal Batch Name", 'COMMISSION');
    JournalLine.Validate("Document No.", NextDocumentNo);
    JournalLine.Validate("Account Type", JournalLine."Account Type"::Employee);
    JournalLine.Validate("Account No.", 'E0001');
    JournalLine.Validate("Bal. Account Type", JournalLine."Bal. Account Type"::"G/L Account");
    JournalLine.Validate(Amount, -5000);
    JournalLine.Insert(true);
    GenJnlPost.Run(JournalLine);
end;
To delete earlier unposted entries, I used this helper method:
local procedure DeleteEarlierUnpostedGenJournalDocs(JournalTemplateName: Code[20]; JournalBatchName: Code[20]; PeekNo: Code[20])
var
    GenJnlLine: Record "Gen. Journal Line";
begin
    GenJnlLine.SetRange("Journal Template Name", JournalTemplateName);
    GenJnlLine.SetRange("Journal Batch Name", JournalBatchName);
    GenJnlLine.SetFilter("Document No.", '<%1', PeekNo);
    if GenJnlLine.FindSet() then
        repeat
            GenJnlLine.Delete(true);
        until GenJnlLine.Next() = 0;
end;
The Problem
Even after deleting all earlier unposted documents, when I run:
GenJnlPost.Run(JournalLine);
Business Central automatically re-populates the deleted lines and then shows the error:
“You have one or more documents that must be posted before you post document no. SC0016 according to your company's No. Series setup.”
It seems BC restores these deleted lines during posting, preventing the new entry from being posted.
What I Tried:
 Deleted earlier unposted entries — they reappear during posting.
 Allowed gaps in No. Series — works but not acceptable for business rules.
 Used PeekNextNo and GetNextNo properly — same issue.
 Tried temporary journal lines — posting fails as persistent records are required.
Still, the issue remains: old unposted entries return automatically before posting.
I have the same question (1)
  • Martin Dráb Profile Picture
    236,471 Most Valuable Professional on at
    Custom Journal Posting Issue in Business Central: No. Series Gaps and Reappearing Entries
    Moved from Integration, Dataverse, and general topics forum to Small and medium business | Business Central, NAV, RMS forum.
  • Ahsan Shahid Profile Picture
    2 on at
    Custom Journal Posting Issue in Business Central: No. Series Gaps and Reappearing Entries

    If the purpose is automation and you don’t need the standard journal UI, use temporary Gen. Journal Line records and call posting routines designed for temp buffers (with TempGenJnlLine variables).

    You will need to handle No. Series manually, but it avoids BC’s built-in reconciliation behavior.

     
  • Suggested answer
    Aman Kakkar Profile Picture
    837 on at
    Custom Journal Posting Issue in Business Central: No. Series Gaps and Reappearing Entries
    Hi,
     
    According to me, there can be two causes for this issue.
     
    1. Try removing - JournalLine.Insert(true); - from your code. I don't think there is any need for inserting the Journal Line when you are directly creating and posting it.
     
    2. I am not sure about this, but you can try changing back the No. Series -> "Last Number Used" while deleting the unposted lines. Even though you physically deleted the lines, you didn’t roll back the No. Series pointer — and Business Central’s “no gaps” enforcement is very strict.
     
    Hope this helps.
    Aman K

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 3,761

#2
Sumit Singh Profile Picture

Sumit Singh 2,611

#3
YUN ZHU Profile Picture

YUN ZHU 1,975 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans