Skip to main content

Notifications

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

Add newly created field in Posting code

(1) ShareShare
ReportReport
Posted on by 54
Hi
 
I have created  fields in Purchase line table with name 'Desc 2' to store more text. When I post the same, I wanted to update this field in GL  Entry , VLE, etc. I request  a sample code for my extension or methods to extend codeunit Post-Purchase line/Post Item jnl
 
warm regards
Krishna
 
  • KK-20050817-0 Profile Picture
    KK-20050817-0 54 on at
    Add newly created field in Posting code
    I have code in my codeunit, my requirements are like G/L account  in Purchase line. In the case of item we can use the following code.
     
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", OnPostItemJnlLineOnAfterCopyDocumentFields, '', false, false)]
        local procedure OnPostItemJnlLineOnAfterCopyDocumentFields(var ItemJournalLine: Record "Item Journal Line"; PurchaseLine: Record "Purchase Line"; WarehouseReceiptHeader: Record "Warehouse Receipt Header"; WarehouseShipmentHeader: Record "Warehouse Shipment Header"; PurchRcptHeader: Record "Purch. Rcpt. Header");
        begin
            ItemJournalLine.Description2 := PurchaseLine."Description 2";
        end;
     
    My company do not use item in Purchase, we use only G/L account. 
     
    warm regards
    krishna
     
     
     
  • Suggested answer
    Add newly created field in Posting code
    Hi,
     
    You can use the below event subscribers.
    Purchase Line to Item Journal Lines
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", OnPostItemJnlLineOnAfterCopyDocumentFields, '', false, false)]
    local procedure OnPostItemJnlLineOnAfterCopyDocumentFields(var ItemJournalLine: Record "Item Journal Line"; PurchaseLine: Record "Purchase Line"; WarehouseReceiptHeader: Record "Warehouse Receipt Header"; WarehouseShipmentHeader: Record "Warehouse Shipment Header"; PurchRcptHeader: Record "Purch. Rcpt. Header");
    begin
    ItemJournalLine."ZY Test" := PurchaseLine."ZY Test";
    end;
     
    Item Journal Lines to Item Ledger Entry
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", OnAfterInitItemLedgEntry, '', false, false)]
    local procedure OnAfterInitItemLedgEntry(var NewItemLedgEntry: Record "Item Ledger Entry"; var ItemJournalLine: Record "Item Journal Line"; var ItemLedgEntryNo: Integer);
    begin
    NewItemLedgEntry."ZY Test" := ItemJournalLine."ZY Test";
    end;
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 77,004 Super User 2025 Season 1 on at
    Add newly created field in Posting code
    Hi, as far as I know, this is a standard field and doesn't need to be recreated. It is recommended that you use it directly.
     
     
    Thanks.
    ZHU
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 13,777 Most Valuable Professional on at
    Add newly created field in Posting code
    Hi
    I hope this can help you and give you some hints. 
    Best regards
    Gerardo

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans