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

Codeunit customization to Auto Post Non-Invt. Items for Dropshipment Sales Orders.

(3) ShareShare
ReportReport
Posted on by 6
Hey Guys,
 
We are using Non-Invt Items with General Prod. Posting Group /FREIGHT/ add freight charges to the Sales and Purchase Orders, instead of Item Charges. 
 
For the Dropshipment orders, we had multiple scenarios where the freight line had to added to Sales Orders, but do not require it in a linked purchase order, as we have our own freighting companies to pick up P.Os from vendor, as forward freight. 
 
For these orders, we cannot automatically post freight lines in Sales Orders, as the freight line is not linked to P.O.
 
 
To address this issue, I am trying to develop a custom codeunit, and using Event handler, I am hoping to post the Sales Lines similar to the /Auto Post Non-Invt. via Whse. / function in BC, as below . 
 
 
I am struck at this stage, as I am struggling to figure out the exact trigger in codeunit: / Purch.-Post /. 
 
Can anyone suggest if I am on the right track, and which trigger I can use in this scenario.
 
Thanks in advance for any help
 
 
 
  • Suggested answer
    Dr Gomathi MVP, MCT Community lead, MLE Profile Picture
    397 Moderator on at

    Hi,

    You’re on the right track, but I wouldn’t try to force the freight line into the normal purchase-line/drop-shipment linkage. The freight charge does not belong on the purchase order, so it should remain an independent sales line.

    For this scenario, the most appropriate subscriber is OnAfterPostPurchaseDocDropShipment in codeunit 90 "Purch.-Post". It runs after Business Central has created the drop-shipment sales shipment and provides the resulting sales shipment number.

    From that event you can:

    1. Get the "Sales Shipment Header" using SalesShptNo.
    2. Use its "Order No." to locate the original sales order.
    3. Find your non-inventory freight line.
    4. Add it to the same sales shipment.
    5. Update "Quantity Shipped" and the related outstanding quantities on the original sales line.

    For example:
    [EventSubscriber(
       ObjectType::Codeunit,
       Codeunit::"Purch.-Post",
       'OnAfterPostPurchaseDocDropShipment',
       '',
       false,
       false)]
    local procedure OnAfterPostPurchaseDocDropShipment(
       SalesShptNo: Code[20];
       CommitIsSuppressed: Boolean;
       PreviewMode: Boolean)
    var
       SalesShptHeader: Record "Sales Shipment Header";
       SalesLine: Record "Sales Line";
    begin
       if PreviewMode then
           exit;

       if SalesShptNo = '' then
           exit;

       if not SalesShptHeader.Get(SalesShptNo) then
           exit;

       SalesLine.SetRange("Document Type", SalesLine."Document Type"::Order);
       SalesLine.SetRange("Document No.", SalesShptHeader."Order No.");
       SalesLine.SetRange(Type, SalesLine.Type::Item);
       SalesLine.SetRange("Gen. Prod. Posting Group", 'FREIGHT');
       SalesLine.SetFilter("Outstanding Quantity", '<>0');

       if SalesLine.FindSet(true) then
           repeat
               PostFreightShipmentLine(SalesShptHeader, SalesLine);
           until SalesLine.Next() = 0;
    end;

     

    PostFreightShipmentLine should create the "Sales Shipment Line" and update the source sales line in the same way that "Sales-Post" handles a non-inventory item. Be careful not to update only "Quantity Shipped" manually; you also need the base quantity, outstanding quantities, "Qty. to Ship", and potentially blanket-order information. Reusing or closely following the standard Sales-Post routines is safer than reproducing only some of the field updates.

    I would not call "Sales-Post" directly from inside "Purch.-Post". That can result in nested posting, commits, locking, number-series issues, and duplicate shipments.

    Also, avoid using OnAfterSalesShptLineInsert for the whole operation. It fires once for every linked drop-shipment line, so a purchase order containing several item lines could create the freight shipment line more than once. If you use that event, you would need explicit duplicate protection.

    One additional recommendation: add a Boolean such as "Auto Ship with Drop Shipment" to the sales line instead of identifying freight only by the /FREIGHT/ posting group. Posting groups are accounting setup; using a dedicated field makes the intended business behaviour clearer and prevents unrelated freight lines from being shipped accidentally.

     

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 768 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 541 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 324 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans