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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Flowing Custom field from Sales Documents to Value Entries

(1) 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!

  • Suggested answer
    Andy Sather Profile Picture
    Microsoft Employee on at

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 740 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 531 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 310 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans