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

Consolidating PDC Line Entries into a Single Journal Entry (Similar to "Apply Entries")

(5) ShareShare
ReportReport
Posted on by 77

Hi everyone,

I hope you're all doing well!

I'm currently working on a custom document type page to maintain Post Dated Cheque (PDC) records in Business Central. In this setup, users can enter multiple lines under a single PDC document.

Now, I want to transfer these multiple line entries to the respective journals—either the Cash Receipt Journal or the Payment Journal—but instead of creating separate entries for each line, I would like to consolidate them into a single journal line, similar to how the "Apply Entries" functionality works in standard processes.

Has anyone implemented something similar or could point me in the right direction on how best to achieve this? Any suggestions, best practices, or code examples would be greatly appreciated.

Thanks in advance for your support!

Best regards,

Govind Sharma

I have the same question (0)
  • Suggested answer
    Sumit Singh Profile Picture
    8,434 on at
    Consolidating PDC Line Entries into a Single Journal Entry (Similar to "Apply Entries")
    Conceptual Approach
    1. Group PDC Lines:
      • Group the lines by key fields like Customer No., Currency Code, Posting Date, etc., depending on your business rules.
      • Sum the Amount field for each group.
    2. Create a Single Journal Line per Group:
      • Use the Gen. Journal Line table (81) to insert a new line for each group.
      • Populate fields like Account Type, Account No., Bal. Account Type, Bal. Account No., Amount, Document No., etc.
    3. Optional: Link Back to PDC Lines:
      • Store a reference (e.g., PDC Document No. or a custom field) in the journal line to trace back to the original PDC lines.

    🧩 Code Snippet (AL Language)
    Sample AL procedure below:
    • Groups PDC lines by PDC Header
    • Sums the amount
    • Inserts a single line into either the Cash Receipt Journal or Payment Journal

    procedure PostConsolidatedPDC(PDCHeader: Record "PDC Header")
    var
        PDCLines: Record "PDC Line";
        GenJnlLine: Record "Gen. Journal Line";
        GenJnlTemplate: Code[10];
        GenJnlBatch: Code[10];
        TotalAmount: Decimal;
        IsReceipt: Boolean;
    begin
        // Define journal template and batch
        GenJnlTemplate := 'CASHRECPT'; // or 'PAYMENT'
        GenJnlBatch := 'DEFAULT';      // adjust as per your setup

        // Determine if it's a receipt or payment
        IsReceipt := PDCHeader."Document Type" = PDCHeader."Document Type"::Receipt;

        // Filter lines for the current PDC document
        PDCLines.SetRange("Document No.", PDCHeader."No.");

        if PDCLines.FindSet() then begin
            repeat
                TotalAmount += PDCLines.Amount;
            until PDCLines.Next() = 0;

            // Insert consolidated journal line
            GenJnlLine.Init();
            GenJnlLine."Journal Template Name" := GenJnlTemplate;
            GenJnlLine."Journal Batch Name" := GenJnlBatch;
            GenJnlLine."Line No." := 10000;
            GenJnlLine."Account Type" :=
                IsReceipt ? GenJnlLine."Account Type"::Customer : GenJnlLine."Account Type"::Vendor;
            GenJnlLine."Account No." := PDCHeader."Account No.";
            GenJnlLine."Document No." := PDCHeader."No.";
            GenJnlLine."Posting Date" := PDCHeader."Posting Date";
            GenJnlLine.Amount := TotalAmount;
            GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::Bank;
            GenJnlLine."Bal. Account No." := PDCHeader."Bank Account No.";
            GenJnlLine.Insert();
        end;
    end;

    🧠 Best Practices
    • Validation: Ensure all PDC lines are valid and approved before posting.
    • Error Handling: Add checks for journal template/batch existence.
    • Posting Preview: Consider adding a preview function before actual posting.
    • Extensibility: Use events/subscribers if you're modifying standard objects.
    • Use GenJournalLine.Insert(true); if you want to trigger validations.
    • Consider using GenJournalLine.TransferFields(...) if you're copying from a template.
    • Add error handling for missing accounts or templates.
    • Optionally, use Codeunit 12 "Gen. Jnl.-Post" to post the journal after insertion.
    Note: This response was developed in collaboration with Microsoft Copilot to ensure clarity and completeness. I hope it helps to some extent.
    Mark the Answer as Verified if this is Helpful.
     
  • Suggested answer
    YUN ZHU Profile Picture
    93,514 Super User 2025 Season 2 on at
    Consolidating PDC Line Entries into a Single Journal Entry (Similar to "Apply Entries")
    It doesn't look that difficult.
    But you need to record the relationship between the merged row and the original row, and you need another posted table to manage the posted PDC.
    There is also the reverse process to consider.
     
    Hope this can give you some hints.
    Thanks.
    ZHU
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,099 Super User 2025 Season 2 on at
    Consolidating PDC Line Entries into a Single Journal Entry (Similar to "Apply Entries")

    I believe you've posted this same question twice. If that's the case, please remove one of them to avoid duplication and help keep the thread clean.

  • Govind_Sharma Profile Picture
    77 on at
    Consolidating PDC Line Entries into a Single Journal Entry (Similar to "Apply Entries")
    Hi,

    You're right — I accidentally posted the same question twice. When I submitted it the first time, I didn’t receive any confirmation or update, so I wasn’t sure if it went through. As a result, I ended up reposting it by mistake.
     
    Unfortunately, I'm unable to delete the duplicate post since it now has a child post attached. Apologies for the confusion, and thanks for your understanding!
  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    8,451 on at
    Consolidating PDC Line Entries into a Single Journal Entry (Similar to "Apply Entries")

    Hi,

    Consolidating PDC lines into a single journal entry can significantly improve both operational clarity and downstream posting efficiency. The goal to replicate “Apply Entries”-like behavior makes perfect sense, especially when you're dealing with grouped financial flows like cheque batches.

    Here's a streamlined approach:

    • Group your PDC Line records logically — typically by Customer No., Document Date, Currency Code, etc.
    • Sum the Amount and map the group to a single Gen. Journal Line. Use standard fields like Account Type, Account No., Posting Date, and optionally extend with a reference field (e.g., PDC Ref. No.) for traceability.
    • Insert the journal line manually or via batch using AL code. Below is a simplified example to get you started:
     
    al
    procedure InsertConsolidatedJournal(PDCHeader: Record "PDC Header")
    var
        PDCLines: Record "PDC Line";
        GenJnlLine: Record "Gen. Journal Line";
        TotalAmt: Decimal;
    begin
        PDCLines.SetRange("Document No.", PDCHeader."No.");
        if PDCLines.FindSet() then begin
            repeat
                TotalAmt += PDCLines.Amount;
            until PDCLines.Next() = 0;
    
            GenJnlLine.Init();
            GenJnlLine."Journal Template Name" := 'CASHRECPT';
            GenJnlLine."Journal Batch Name" := 'DEFAULT';
            GenJnlLine."Posting Date" := PDCHeader."Posting Date";
            GenJnlLine."Document No." := PDCHeader."No.";
            GenJnlLine."Account Type" := GenJnlLine."Account Type"::Customer;
            GenJnlLine."Account No." := PDCHeader."Account No.";
            GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::Bank;
            GenJnlLine."Bal. Account No." := PDCHeader."Bank Account No.";
            GenJnlLine.Amount := TotalAmt;
            GenJnlLine.Insert();
        end;
    end;
    
     

    To align closer with “Apply Entries” logic, you could reference individual line entries using a dimension or custom field for linkage, without cluttering the journal itself. If needed, you can also trigger a notification or review flow before posting.

    Helpful Reference
    How to Avoid the "You cannot set Applies-to ID while selecting Applies-to Doc. No." Error in Dynamics 365 BC | Stoneridge Software


    If you find this helpful, feel free to mark this as the suggested or verified answer.

    Cheers
    Jeffrey

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,056

#2
YUN ZHU Profile Picture

YUN ZHU 1,680 Super User 2025 Season 2

#3
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,679

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans