I have 2 custom fields made on the headers of Sales Order, Sales Invoice, Sales Credit Memo, Posted Sales Credit Memo, and Posted Sales Invoice. And they are also on lines as a flowfield Lookup just in case I want to refer to them on the line in any future customization (saves time going finding header).
The fields are;
Final Customer Code [20
Final Customer Name [150
I intend to flow these to the Value Entries table once a Sales Order or Sales Invoice is posted or Sales Credit Memo is posted. For all those mentioned documents a Value Entry line is created for sure, I just had to create the same fields in the table of Value Entries and find a suitable Event Subscriber.
The only Event I manage to find and wrote my code was as below;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesLine', '', true, true)] local procedure OnAfterPostSalesLine(var SalesHeader: Record "Sales Header"; var SalesInvLine: Record "Sales Invoice Line"; var SalesCrMemoLine: Record "Sales Cr.Memo Line"); var rec_ValEntry: Record "Value Entry"; rec_CU: Codeunit cu; comp: Text; begin Clear(comp); comp := CompanyName; if comp = 'FZC' then begin if (SalesHeader."Document Type" = SalesHeader."Document Type"::Order) then begin rec_CU.ModifyValueEntryLineofSalesInv(SalesInvLine); end; if (SalesHeader."Document Type" = SalesHeader."Document Type"::"Credit Memo") then begin rec_CU.ModifyValueEntryLineofSalesCrMemo(SalesCrMemoLine); end; end; // in a new codeunit .al file codeunit 50005 "CU" { Permissions = tabledata "Value Entry" = RIMD; procedure ModifyValueEntryLineofSalesInv(var SalesInvLine: Record "Sales Invoice Line") var rec_ValEntry: Record "Value Entry"; rec_SalesInvHeader: Record "Sales Invoice Header"; begin rec_ValEntry.Reset(); Clear(rec_ValEntry); rec_SalesInvHeader.Reset(); Clear(rec_SalesInvHeader); rec_SalesInvHeader.SetRange("No.", SalesInvLine."Document No."); if rec_SalesInvHeader.FindFirst() then begin rec_ValEntry.SetRange("Document Type", rec_ValEntry."Document Type"::"Sales Invoice"); rec_ValEntry.SetRange("Document No.", rec_SalesInvHeader."No."); if rec_ValEntry.FindFirst() then begin rec_ValEntry."LLC Customer" := rec_SalesInvHeader."Final LLC Customer"; rec_ValEntry."LLC Customer Name" := rec_SalesInvHeader."Final LLC Customer Name"; rec_ValEntry.Modify(); end; end; end; procedure ModifyValueEntryLineofSalesCrMemo(var SalesCrMemo: Record "Sales Cr.Memo Line") var rec_ValEntry: Record "Value Entry"; rec_SalesCreHeader: Record "Sales Cr.Memo Header"; begin rec_ValEntry.Reset(); Clear(rec_ValEntry); rec_SalesCreHeader.Reset(); Clear(rec_SalesCreHeader); rec_SalesCreHeader.SetRange("No.", SalesCrMemo."Document No."); if rec_SalesCreHeader.FindFirst() then begin rec_ValEntry.SetRange("Document Type", rec_ValEntry."Document Type"::"Sales Credit Memo"); rec_ValEntry.SetRange("Document No.", rec_SalesCreHeader."No."); if rec_ValEntry.FindFirst() then begin rec_ValEntry."LLC Customer" := rec_SalesCreHeader."Final LLC Customer"; rec_ValEntry."LLC Customer Name" := rec_SalesCreHeader."Final LLC Customer Name"; rec_ValEntry.Modify(); end; end; end; .. .. .. .. end;
however, this Event subscriber still misses flowing the value to Value Entries so I was here to ask if there is another Event I can use that on Posting my SO, SI, Sales Credit Memo can flow my fields to value entries table.
Thanks a lot for the advice in advance!