Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Flowing Custom field from Sales Documents to Value Entries

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!

  • Mesam Profile Picture
    Mesam 95 on at
    RE: Flowing Custom field from Sales Documents to Value Entries

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

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Flowing Custom field from Sales Documents to Value Entries

    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..................

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans