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 :

Auto-Posting Intercompany Gen. Journal Lines in Partner Company

Aman Kakkar Profile Picture Aman Kakkar 458

Hi everyone 👋,

If you genuinely want to understand how to implement Auto-Posting, read this post line by line. It’s not just about the final solution — it’s about learning how to think logically when solving a problem that doesn’t have a predefined answer — where you are the one creating it.

(I have added emojis in this blog to make it more interactive.)


The Problem

Automatic posting of Intercompany General Journals in the partner company as soon as the Intercompany Journals were posted in the base company.

After searching extensively online — including forums, documentation, and even AI tools — I couldn’t find any working solution. So, I built one myself.


The Key Discovery

I found an event that triggers after Intercompany Journal Lines are inserted in the partner company — this was the breakthrough.

The event is:

👉 OnAfterCreateJournalLines in Codeunit 427 – ICInboxOutboxMgt

This event fires every time new Intercompany Journal Lines are inserted, dimensions are mapped, and the IC Inbox Transactions are moved to “Handled” in the partner company — the perfect point to execute our auto-posting logic.


💡 The Logic

Let’s take a simple example.

Suppose your Intercompany Journal has 6 lines with these amounts:

100, -100, 200, 300, -200, -300

When the first line (100) is inserted, the total balance isn’t zero — so we skip posting.

When the second line (-100) is inserted, the total becomes 0, meaning the batch is balanced — and now we auto-post.

We continue the same pattern: only when the total balance equals zero, the batch is posted automatically.


The Foundation — Adding an Identifier

To ensure that only the relevant IC journal lines are auto-posted, we add an identifier. For this, create a new Boolean field in the Gen. Journal Line table, e.g., Auto-Posting.

You’ll then need to pass this flag through each step of the Intercompany process until it reaches the posting event.

Here’s how:

[EventSubscriber(ObjectType::Codeunit, Codeunit::ICInboxOutboxMgt, 'OnInsertOutboxJnlLineOnBeforeICOutboxJnlLineInsert', '', false, false)]
local procedure OnInsertOutboxJnlLineOnBeforeICOutboxJnlLineInsert(var ICOutboxJnlLine: Record "IC Outbox Jnl. Line"; TempGenJournalLine: Record "Gen. Journal Line" temporary)
begin
    if (TempGenJournalLine."Journal Template Name" = Setup."IC Journal Template") then
        ICOutboxJnlLine."Auto-Posting" := true;
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::ICInboxOutboxMgt, 'OnOutboxJnlLineToInboxOnBeforeICInboxJnlLineInsert', '', false, false)]
local procedure OnOutboxJnlLineToInboxOnBeforeICInboxJnlLineInsert(var ICInboxJnlLine: Record "IC Inbox Jnl. Line"; var ICOutboxJnlLine: Record "IC Outbox Jnl. Line")
begin
    ICInboxJnlLine."Auto-Posting" := ICOutboxJnlLine."Auto-Posting";
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::ICInboxOutboxMgt, 'OnBeforeInsertGenJnlLine', '', false, false)]
local procedure OnBeforeInsertGenJnlLine(var GenJnlLine: Record "Gen. Journal Line"; ICInboxJnlLine: Record "IC Inbox Jnl. Line")
begin
    if ICInboxJnlLine."Auto-Posting" then
        GenJnlLine."Auto-Posting" := true;
end;

🚀 The Auto-Posting Logic

Finally, we handle the posting itself using the event OnAfterCreateJournalLines:

[EventSubscriber(ObjectType::Codeunit, Codeunit::ICInboxOutboxMgt, 'OnAfterCreateJournalLines', '', false, false)]
local procedure OnAfterCreateJournalLines(var GenJnlLine2: Record "Gen. Journal Line")
var
    GenJnlLines: Record "Gen. Journal Line";
    GenJnlPost: Codeunit "Gen. Jnl.-Post";
    TotalAmt: Decimal;
begin
    if not GenJnlLine2."Auto-Posting" then
        exit;

    GenJnlLines.Reset();
    GenJnlLines.SetRange("Journal Template Name", GenJnlLine2."Journal Template Name");
    GenJnlLines.SetRange("Journal Batch Name", GenJnlLine2."Journal Batch Name");
    GenJnlLines.SetRange("Document No.", GenJnlLine2."Document No.");
    GenJnlLines.SetRange("Auto-Posting", true);

    GenJnlLines.CalcSums(Amount);
    TotalAmt := GenJnlLines.Amount;

    if TotalAmt = 0 then
        if GenJnlLines.FindSet() then
            GenJnlPost.Run(GenJnlLines);
end;

And just like that — the Intercompany Journals post automatically when they’re balanced.

💥 Simple, clean, and effective.​​​​​​​


🧠 Key Takeaway

This solution doesn’t just automate posting — it shows how understanding the event flow and data movement in Business Central can help you build solutions that don’t exist yet.

If you’ve ever struggled with Intercompany automation, I hope this helps you save hours of trial and error.


💬 Closing Note

If this helped you or sparked new ideas, leave a comment or share your approach!

Let’s keep building smarter solutions together for the BC community. 💪


Comments