[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;
Answers
Process -- sales order ---post ---ship & invoice
"Value Entries" are created from "Item Journal Lines". Which in turn are created from the document lines. Follow this logic and the available events to bring your fields to these tables.
Look at how the standard process flows field values from the documents to the ledgers. Use that as your guide. There should be events along that path you can use.
you lost me at the terrible variable naming.
Please listen to the advise given by bbrown, he really knows what he is talking about.
codeunit 50004 U_UpdateValeEnty
{
[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;
}
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.U_CustomerCode := rec_SalesInvHeader."Sell-to Customer No.";
rec_ValEntry.U_CustomerName := rec_SalesInvHeader."Sell-to 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.U_CustomerCode := rec_SalesCreHeader."Sell-to Customer No.";
rec_ValEntry.U_CustomerName := rec_SalesCreHeader."Sell-to Customer Name";
rec_ValEntry.Modify();
end;
end;
end;
}
codeunit 50001 U_UpdateValueEntry
{
Permissions = tabledata "Value Entry" = RIMD;
[EventSubscriber(ObjectType::Codeunit, 22, 'OnafterInsertValueEntry', '', false, false)]
local procedure OnBeforeInsertValueEntry(var ValueEntry: Record "Value Entry")
var
SalesInvHeader: Record "Sales Invoice Header";
SalesCrMemoHdr: Record "Sales Cr.Memo Header";
begin
if (ValueEntry."Item Ledger Entry Type" = ValueEntry."Item Ledger Entry Type"::Sale) then
case ValueEntry."Document Type" of
ValueEntry."Document Type"::"Sales Credit Memo":
begin
if SalesCrMemoHdr.Get(ValueEntry."Document No.") then;
ValueEntry.Description := SalesCrMemoHdr."Sell-to Customer Name";
//ValueEntry.Description := SalesCrMemoHdr."Final LLC Customer Name";
end;
ValueEntry."Document Type"::"Sales Invoice":
begin
if SalesInvHeader.Get(ValueEntry."Document No.") then;
//ValueEntry.Validate(Description, SalesInvHeader."Sell-to Customer Name");
SalesInvHeader.CalcFields(U_CustomerName2);
ValueEntry.Validate(Description, SalesInvHeader.U_CustomerName2);
ValueEntry.Modify()
end;
end;
end;
}
You do this by moving your field values to the "ItemJnlLine" when it's created in CU 80. I'll leave you to sort that part out.