Skip to main content
Community site session details

Community site session details

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

Copy Sales Order Quantity to Posted Sales Invoice Line - Event to subscribe

(0) ShareShare
ReportReport
Posted on by 2,975

Hi All

I'm trying to copy sales order (original) quantity to posted Invoice line user field. This is to calculate back order quantity and show on posted invoice. The event below did not work:

[EventSubscriber(ObjectType::Codeunit, 80, 'OnAfterSalesInvLineInsert', '', false, false)]
Looks like SO gets deleted before this event
Is there any other event I can use
Thanks
  • Verified answer
    YUN ZHU Profile Picture
    86,253 Super User 2025 Season 1 on at
    RE: Copy Sales Order Quantity to Posted Sales Invoice Line - Event to subscribe

    Hi, try the follwoing.

    tableextension 80122 MyExtension extends "Sales Invoice Line"
    {
        fields
        {
            field(50100; OrigianlQuantity; Decimal)
            {
                DataClassification = CustomerContent;
            }
        }
    }
    
    pageextension 80122 MyExtension extends "Posted Sales Invoice Subform"
    {
        layout
        {
            addafter(Quantity)
            {
                field(OrigianlQuantity; Rec.OrigianlQuantity)
                {
                    ApplicationArea = All;
                }
            }
        }
    }
    
    codeunit 80122 MyCodeunit
    {
    
        Permissions = tabledata "Sales Invoice Line" = rimd;
    
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterPostSalesLine', '', false, false)]
        local procedure OnAfterPostSalesLine(var SalesLine: Record "Sales Line"; var SalesInvLine: Record "Sales Invoice Line");
        begin
            SalesInvLine.OrigianlQuantity := SalesLine.Quantity;
            SalesInvLine.Modify();
        end;
    }

    pastedimage1642984075582v2.png

    pastedimage1642984096164v3.png

    Hope this will help.

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Copy Sales Order Quantity to Posted Sales Invoice Line - Event to subscribe

    I would recommend you to try the "OnBeforeSalesInvLineInsert" event in the same codeunit.

    Butif there is a back order quantity on the line the sales line should anyway not be deleted?

    Only sales lines that are fully invoiced will be deleted during post.

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans