Skip to main content

Notifications

Business Central forum
Unanswered

Passing custom field on sales line to G/L Entry

Posted on by 87
HI All,
 
Here's the scenario.
A new field was created on the sales line - which holds tax information. I was able to transfer this amount to the customer ledger and detailed customer ledger entries.
I'm having an issue with being able to pass this value to the G/L entry when the sales invoice is posted.
 
I need it to create a line for the value on the GL Entry.
 
I wrote the proc below but it's not working.
codeunit 50109 WSBCareAPICASITaxRotuine
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', false, false)]
    local procedure OnAfterSalesInvoicePost(SalesHeader: Record "Sales Header")
    var
        GLAcc: Record "G/L Account";
        GenJnlLine: Record "G/L Entry";
        SalesLine: Record "Sales Line";
        CSI_TaxAmount: Decimal;
    begin
        SalesLine.SetRange("Document Type", SalesLine."Document Type"::Invoice);
        SalesLine.SetRange("Document No.", SalesHeader."No.");
 
        if SalesLine.FindSet() then
            repeat
                if SalesLine."CSI Tax" <> 0 then
                    CSI_TaxAmount := SalesLine."CSI Tax";
 
                if CSI_TaxAmount <> 0 then begin
                    GenJnlLine.Init();
                    GenJnlLine."G/L Account No." := '2350'
                    GenJnlLine."Posting Date" := SalesHeader."Posting Date";
                    GenJnlLine.Description := 'CSI Tax for Sales Invoice ' + SalesHeader."No.";
                    GenJnlLine.Amount := CSI_TaxAmount;
                    GenJnlLine.Insert(true);
 
                     CODEUNIT.Run(Codeunit::"Gen. Jnl.-Post Line", GenJnlLine);
                end;
            until SalesLine.Next() = 0;
    end;
}
 
Any ideas?
 
Side note - this is being done as a make shift solution until the client implements a tax provider next year. I know its not the best... its a work around for now- they need the tax info on the same line - they dont want to pass a new line just for taxes.
  • Hein Kruger Profile Picture
    Hein Kruger 458 on at
    Passing custom field on sales line to G/L Entry
    Most likely there are no more lines to find. 
    OnAfterPostSalesDoc means the 
    Sales Order turned into a Posted Sales Invoice
    When this happens the document and the lines gets deleted after being processed. 
    The Sales Header Table was transferred to the Posted Sales Invoice Header Table.
    The Sales Lines Table was transferred to the Sales Invoice Lines Record. 

    Either use an earlier trigger when the Sales Lines are being processed. 
    Something Like OnRunOnBeforePostSalesLineEndLoop in codeunit 80 "Sales-Post".

    Or use your current eventSubscriber and find the related Posted Sales Invoice Lines.

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans