You can easily do it using the following sequence of Standard Events for transferring data from Purchase Line to GL Entry for a custom field.
Firstly create the "Custom Field" in the table extensions for Purchase Line, Invoice Posting Buffer, Gen. Journal Line and G/L Entry. Then go ahead with the below mentioned sequence of code.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Post Invoice Events", 'OnPrepareLineOnAfterFillInvoicePostingBuffer', '', false, false)]
local procedure OnPrepareLineOnAfterFillInvoicePostingBuffer(var InvoicePostingBuffer: Record "Invoice Posting Buffer"; PurchLine: Record "Purchase Line"; var TempInvoicePostingBuffer: Record "Invoice Posting Buffer" temporary; var FALineNo: Integer; var InvDefLineNo: Integer; var DeferralLineNo: Integer; var IsHandled: Boolean)
begin
InvoicePostingBuffer."Custom Field" := PurchLine."Custom Field";
end;
STEP 02: Invoice Posting Buffer -> Gen. Journal Line
Use 'OnPrepareGenJnlLineOnAfterCopyToGenJnlLine' from Codeunit "Purch. Post Invoice Events"
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch. Post Invoice Events", 'OnPrepareGenJnlLineOnAfterCopyToGenJnlLine', '', false, false)]
local procedure OnPrepareGenJnlLineOnAfterCopyToGenJnlLine(var GenJnlLine: Record "Gen. Journal Line"; PurchHeader: Record "Purchase Header"; InvoicePostingBuffer: Record "Invoice Posting Buffer")
begin
GenJnlLine."Custom Field" := InvoicePostingBuffer."Custom Field";
end;
STEP 03: Gen. Journal Line -> G/L Entry
Use 'OnAfterInitGLEntry' from Codeunit "Gen. Jnl.-Post Line"
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnAfterInitGLEntry', '', false, false)]
local procedure OnAfterInitGLEntry(var GLEntry: Record "G/L Entry"; GenJournalLine: Record "Gen. Journal Line"; Amount: Decimal; AddCurrAmount: Decimal; UseAddCurrAmount: Boolean; var CurrencyFactor: Decimal; var GLRegister: Record "G/L Register")
begin
GLEntry."Custom Field" := GenJournalLine."Custom Field";
end;
And that's it. You are done. Please do upvote and move it to Answers if you feel it helped you.