/
Case: Add Header Step (Shipping Agent Service Code)

Case: Add Header Step (Shipping Agent Service Code)

Minimum Requirements

Extension version MOB5.27 
Android App 1.5.9

Case

Ask the user for what Shipping Agent and Service Code during Warehouse pick posting

Proposed solution

The user will be asked for Shipping Agent and Service Code during Warehouse pick posting.

The collected values will be used to update the associated Warehouse Shipment Header.


Limitations

  • No check for multiple orders. Assumes you work with only one Sales Order per Warehouse Shipment
  • No check for whether Shipping Agent Service code has already been set on Shipment


Example code

Using OnPostPickOrder_OnAddStepsToWarehouseActivityHeader event which is called repeatedly to: 

  • Collect two steps- one after the other 
    • Value from the first step is used to filter the second step

  • Finally, update the Warehouse Shipment the collected values  


    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnPostPickOrder_OnAddStepsToWarehouseActivityHeader', '', true, true)]
    local procedure MyOnPostPickOrder_OnAddStepsToWarehouseActivityHeader(var _OrderValues: Record "MOB Common Element"; _WhseActivityHeader: Record "Warehouse Activity Header"; var _StepsElement: Record "MOB Steps Element")
    var
        ShippingAgent: Record "Shipping Agent";
        ShippingAgentServices: Record "Shipping Agent Services";
        WarehouseActivityLine: Record "Warehouse Activity Line";
        WarehouseShipmentHeader: Record "Warehouse Shipment Header";
        ListValues: Text;
    begin
        // First run: Collect Shipping Agent
        if not _OrderValues.HasValue('ShippingAgent') then begin
            if ShippingAgent.FindSet() then begin
                repeat
                    ListValues += ';' + ShippingAgent.Code;
                until ShippingAgent.Next() = 0;
                _StepsElement.Create_ListStep(1, 'ShippingAgent', 'Agent Service');
                _StepsElement.Set_listValues(ListValues);
            end;
            exit; // Exit before the second step
        end;



        // Second run: Collect Shipping Agent Service based on First step value
        if not _OrderValues.HasValue('ShippingAgentService') then begin
            ShippingAgentServices.SetFilter("Shipping Agent Code", '%1', _OrderValues.GetValue('ShippingAgent')); // Use first step value as filter for second step
            if ShippingAgentServices.FindSet() then begin
                repeat
                    ListValues += ';' + ShippingAgentServices.Code;
                until ShippingAgentServices.Next() = 0;
                _StepsElement.Create_ListStep(2, 'ShippingAgentService', 'Shipping Agent Service');
                _StepsElement.Set_listValues(ListValues);
                exit; // Exit before the last run
            end;
        end;

        // Last run: Both Agent and Service code has now been collected
        // Update Shipment with collected values
        WarehouseActivityLine.SetRange("No.", _WhseActivityHeader."No.");
        if WarehouseActivityLine.FindFirst() then
            if WarehouseShipmentHeader.Get(WarehouseActivityLine."Whse. Document No.") then begin
                WarehouseShipmentHeader.Validate("Shipping Agent Code", _OrderValues.GetValue('ShippingAgent'));
                WarehouseShipmentHeader.Validate("Shipping Agent Service Code", _OrderValues.GetValue('ShippingAgentService'));
                WarehouseShipmentHeader.Modify();
            end;
    end;

Similar available events

See also 


First step

Second step