Skip to main content

Notifications

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

Automatically adding an item to the sales order

Posted on by Microsoft Employee

Hi,

I have a problem related to Sales orders. In our business we very often sell certain products (let's call it item A) which requires to add a non-inventory item (Item B) to the sales order. For example:

Sales order:

1. We add Item A 100 pcs X price

2. We add Item B 100 pcs Y price (mandatory addition, if Item A is added to a sales order)

As we always need to add the Item B, it would make sense to automate adding it. However, we are quite new to the Business Central world so I don't really know where to start figuring this out. Logically the easiest solution would be some sort of automation that basically would automatically add the item B on the sales order after inputting Item A to a sales order. However, I don't have any idea if this is possible?

There must be some way to handle this, as I feel this is fairly common issue?

All help or comments are appreciated!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Automatically adding an item to the sales order

    For any other folks battling this issue. Akshay's code is a very prominent solution, especially if the need is just to add one additional item to the order. If you get the code working, this is really helpful as it's fully automated.

    Ben's solution through Assembly Management functionality is the way to go when there are multiple line's to be added for a certain item. However, this requires a couple of clicks from mouse so it's not the most quickest solution. However, those clicks are worth it, especially if sold item consists of multiple different/complex set of items with different quantities. For example, if salesperson is selling a product XYZ, he/she doesn't have to remember the composition of XYZ, just add that product through the Assembly Management and then break the item down on the Sales order.

    Example:

    1. Salesperson put's 1 XYZ item on the order.

    2. Salesperson navigates to Row -> Functions -> Explode BOM

    3. This item turns into a comment line and below that you can find the items with correct quantities set up through Assembly management.

    Comment: Item XYZ

    Item X 3 pcs

    Item Y 6 pcs

    Item Z 9 pcs

    This way salesperson doesn't need to remember how many X, Y or Z is in the Item XYZ. Salesperson is only required to set how many Item XYZ customer needs.

  • Verified answer
    Ben Baxter Profile Picture
    Ben Baxter 4,915 Super User 2024 Season 2 on at
    RE: Automatically adding an item to the sales order

    While the above customization would work in the scenario where you only need to add 1 additional Item, it will become more clunky if you need to add 3 additional products when you add the first.

    You could look at using the standard Assembly Management functionality within BC.  This would allow you to explode the components onto the lines for visibility.

    Assembly Mgmt. would also allow you to pre-pack the bundles so you don't forget to add them at time of shipment.

  • Verified answer
    Akshay_Panchal Profile Picture
    Akshay_Panchal 402 on at
    RE: Automatically adding an item to the sales order

    Hi,

    You have to right code after Insert A item code on line.After this insertion of A line you can right code for the insertion of b line.

    So you have to call eventsubscriber as below

     [EventSubscriber(ObjectType::Table37'OnAfterInsertEvent''', true, true)]
        local procedure OnAfterInsertEventSalesLine(var Rec: Record "Sales Line")
        var
            SalesLine: Record "Sales Line";
            LastSalesLine: Record "Sales Line";
            LineNo: Integer;
        begin
            if Rec."No." = '1000' then begin
                LineNo := 0;

                LastSalesLine.Reset();
                LastSalesLine.SetRange("Document Type", Rec."Document Type");
                LastSalesLine.SetRange("Document No.", Rec."Document No.");
                if LastSalesLine.FindLast() then
                    LineNo := LastSalesLine."Line No." + 10000
                else
                    LineNo := 10000;

                SalesLine.Init();
                SalesLine."Document No." := Rec."Document No.";
                SalesLine."Document Type" := Rec."Document Type";
                SalesLine."Line No." := LineNo;
                SalesLine.Insert(true);
                SalesLine.Validate(Type, SalesLine.Type::Item);
                SalesLine.Validate("No.", '1100');
                SalesLine.Modify();

            end;
        end;
    If you enter the 1000 item code system will auto add the 1100 item line on order according to above code.
    Also you can set dynamic with adding field Sub Item No. on Item Table so system will auto create line base on the field.
    see above code output as below
    pastedimage1635161397905v1.png

    Verify, If this answer helpful for you

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans