DEV Community

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

Posted on • Edited on

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

Top comments (0)