DEV Community

Cover image for Splitting Warehouse Shipment lines in multiple headers in Business Central
Xavier Garonnat
Xavier Garonnat

Posted on • Edited on

3 3

Splitting Warehouse Shipment lines in multiple headers in Business Central

AL extensibility challenge : how to spread automatically Warehouse Shipment Lines on multiple Warehouse Shipment Header without being too much intrusive ? (with the constraint that the count of lines per document should now exceed a fixed value)

Just find the right event in the "Get Source Document" report and force the creation of a new header by setting WhseHeaderCreated to false when the condition is met :-)

    [EventSubscriber(ObjectType::Report, Report::"Get Source Documents", 'OnSalesLineOnAfterGetRecordOnBeforeCreateShptHeader', '', false, false)]
    local procedure OnSalesLineOnAfterGetRecordOnBeforeCreateShptHeader(SalesLine: Record "Sales Line"; var WarehouseRequest: Record "Warehouse Request"; var WarehouseShipmentHeader: Record "Warehouse Shipment Header"; var WhseHeaderCreated: Boolean; var OneHeaderCreated: Boolean; var IsHandled: Boolean);
    var
        WhseShipmentLine: Record "Warehouse Shipment Line";
    begin

        IF WarehouseShipmentHeader."No." = '' then
            exit;

        WhseShipmentLine.Reset();
        WhseShipmentLine.SetRange("No.", WarehouseShipmentHeader."No.");
        if WhseShipmentLine.Count = <MaxLinePerDocument> then
            WhseHeaderCreated := false; //create new Whse Shipment Header

    end;


Enter fullscreen mode Exit fullscreen mode

I like simplicity :-)

Edit : the event is located here
Image description

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay