web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Flowing Custom field from Sales Documents to Value Entries

(0) ShareShare
ReportReport
Posted on by 95

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!

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Hi Abbas,

    Can you please use EventSubscriber as per below and take appropriate functions and then check

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterSalesInvLineInsert', '', true, true)]

    function..................

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post",'OnAfterSalesCrMemoLineInsert', '', true, true)]

    function..................

  • Mesam Profile Picture
    95 on at

    At those event you suggest I go find a value entry it has raised and modify it?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,606

#2
YUN ZHU Profile Picture

YUN ZHU 931 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans