Thanks Yun Zhu and Valentin for your responses.
I have edited my Question for better understanding. Also, I have got the solution for this. I used the below mentioned event (and code) and I was able to post some more lines along with purchase invoice, which acted the same way as the standard lines i.e. they were showing up in the Preview Posting -> Find Entries, as well as after Posting along with the Posted Document.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Post Invoice Events", 'OnPostLedgerEntryOnBeforeGenJnlPostLine', '', false, false)]
local procedure OnPostLedgerEntryOnBeforeGenJnlPostLine(var GenJnlLine: Record "Gen. Journal Line"; PurchHeader: Record "Purchase Header"; TotalPurchLine: Record "Purchase Line"; TotalPurchLineLCY: Record "Purchase Line"; PreviewMode: Boolean; SuppressCommit: Boolean; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line")
var
PurchLine: Record "Purchase Line";
begin
if PurchHeader."Document Type" <> PurchHeader."Document Type"::Invoice then
exit;
PurchLine.Reset();
PurchLine.SetRange("Document Type", PurchHeader."Document Type");
PurchLine.SetRange("Document No.", PurchHeader."No.");
PurchLine.SetRange(Type, PurchLine.Type::"G/L Account");
if PurchLine.FindSet() then
repeat
CreateAndPostGenJournalNegativeLine(PurchHeader, PurchLine, GenJnlPostLine, GenJnlLine);
CreateAndPostGenJournalPositiveLine(PurchHeader, PurchLine, GenJnlPostLine, GenJnlLine);
until PurchLine.Next() = 0;
end;
For creating a reversal(negative) amount line:
procedure CreateAndPostGenJournalReversalLine(PurchHeader: Record "Purchase Header"; PurchLine: Record "Purchase Line"; var GenJnlPostLine: codeunit "Gen. Jnl.-Post Line"; var VarGenJnlLine: Record "Gen. Journal Line")
var
ReversalJnlLine: Record "Gen. Journal Line";
begin
Setup.Get();
Clear(ReversalJnlLine);
ReversalJnlLine.Init();
ReversalJnlLine."Journal Template Name" := Setup."Journal Template";
ReversalJnlLine."Journal Batch Name" := Setup."Journal Batch";
ReversalJnlLine."Line No." := GetNextLineNoForGenJnl(ReversalJnlLine."Journal Template Name", ReversalJnlLine."Journal Batch Name");
ReversalJnlLine.Validate("Account Type", ReversalJnlLine."Account Type"::"G/L Account");
ReversalJnlLine.Validate("Account No.", PurchLine."No.");
ReversalJnlLine.Validate("Posting Date", PurchHeader."Posting Date");
ReversalJnlLine.Validate("Document Type", ReversalJnlLine."Document Type"::" ");
ReversalJnlLine.Validate("Document No.", VarGenJnlLine."Document No.");
ReversalJnlLine.Validate(Amount, -PurchLine."Amount Including VAT");
ReversalJnlLine.Validate("Dimension Set ID", PurchLine."Dimension Set ID");
ReversalJnlLine.Validate("Gen. Posting Type", VarGenJnlLine."Gen. Posting Type");
ReversalJnlLine.Validate("Gen. Prod. Posting Group", VarGenJnlLine."Gen. Prod. Posting Group");
ReversalJnlLine.Validate("Gen. Prod. Posting Group", VarGenJnlLine."Gen. Prod. Posting Group");
ReversalJnlLine."Is Reversal Line" := true;
ReversalJnlLine.Insert();
GenJnlPostLine.RunWithCheck(ReversalJnlLine);
end;
For creating a positive amount line (Just the Amount is taken as positive, else everything is same.
procedure CreateAndPostGenJournalPositiveLine(PurchHeader: Record "Purchase Header"; PurchLine: Record "Purchase Line"; var GenJnlPostLine: codeunit "Gen. Jnl.-Post Line"; var VarGenJnlLine: Record "Gen. Journal Line")
var
ReversalJnlLine: Record "Gen. Journal Line";
begin
Setup.Get();
Clear(ReversalJnlLine);
ReversalJnlLine.Init();
ReversalJnlLine."Journal Template Name" := Setup."Journal Template";
ReversalJnlLine."Journal Batch Name" := Setup."Journal Batch";
ReversalJnlLine."Line No." := GetNextLineNoForGenJnl(ReversalJnlLine."Journal Template Name", ReversalJnlLine."Journal Batch Name");
ReversalJnlLine.Validate("Account Type", ReversalJnlLine."Account Type"::"G/L Account");
ReversalJnlLine.Validate("Account No.", PurchLine."No.");
ReversalJnlLine.Validate("Posting Date", PurchHeader."Posting Date");
ReversalJnlLine.Validate("Document Type", ReversalJnlLine."Document Type"::" ");
ReversalJnlLine.Validate("Document No.", VarGenJnlLine."Document No.");
ReversalJnlLine.Validate(Amount, PurchLine."Amount Including VAT");
ReversalJnlLine.Validate("Dimension Set ID", PurchLine."Dimension Set ID");
ReversalJnlLine.Validate("Gen. Posting Type", VarGenJnlLine."Gen. Posting Type");
ReversalJnlLine.Validate("Gen. Prod. Posting Group", VarGenJnlLine."Gen. Prod. Posting Group");
ReversalJnlLine.Validate("Gen. Prod. Posting Group", VarGenJnlLine."Gen. Prod. Posting Group");
ReversalJnlLine."Is Reversal Line" := true;
ReversalJnlLine.Insert();
GenJnlPostLine.RunWithCheck(ReversalJnlLine);
end;