Extension version MOB5.23


Print Label on the posting of Tote Shipping.

Proposed solution

  • You want to print labels from the mobile device
  • You want to use the integrated Cloud Print Service solution
  • The label should be printed automatically when shipping totes

Step 1: Create Header steps

In order to determine when, where and what to print, we add a step when Post Tote-shipping.

Add the following code to create a step on posting.

See also: OnGetRegistrationConfiguration_OnAddSteps   

[EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Adhoc Registr.", 'OnGetRegistrationConfiguration_OnAddSteps''', true, true)]
    local procedure MyOnGetRegistrationConfiguration_OnAddSteps(_RegistrationType: Textvar _HeaderFieldValues: Record "MOB NS Request Element"; var _Steps: Record "MOB Steps Element"; var _RegistrationTypeTracking: Text)
        MobWmsToolbox: Codeunit "MOB WMS Toolbox";
        MobPrint: Codeunit "MOB Print";
        // Verify this should only affects Tote-shipping
        if _RegistrationType <> MobWmsToolbox."CONST::ToteShipping"() then

        _Steps.Set_header('Label print');
        _Steps.Set_listValues(' ;' + MobPrint.GetMobilePrinters('Item Label 3x2', ''))// Allow user to select blank printer + the printers attached to this labeltemplate
        _Steps.Set_helpLabel('If you want a label, please select a printer.');

Step 2:  Handle step and issue print

    // We read the collected step (printer).
    // Issue a print based on printer, label and the current context (Posted Shipment Line)
    // Print engine will build a dataset
    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Adhoc Registr.", 'OnPostAdhocRegistration_OnAfterPostToteShipping''', true, true)]
    local procedure OnPostAdhocRegistration_OnAfterPostToteShipping(_WhseShipmentLine: Record "Warehouse Shipment Line"; var _RequestValues: Record "MOB NS Request Element"; var _SuccessMessage: Text)
        TempPrintParameter: Record "MOB Print REST Parameter" temporary;
        MobPrinter: Record "MOB Printer";
        Item: Record Item;
        MobPrint: Codeunit "MOB Print";
        MobLanguage: Codeunit "MOB WMS Language";
        MobWmsToolbox: Codeunit "MOB WMS Toolbox";
        MobPrintBuffer: Codeunit "MOB Print Buffer";
        RecRef: RecordRef;
        PrintCommand: Text;

        // Verify this should only affects Tote-shipping
        if _RequestValues.GetValue('RegistrationType'<> MobWmsToolbox."CONST::ToteShipping"() then

        // -- Prepare to Print
        // Did user select a printer?
        if _RequestValues.GetValue('Printer'' ' then

        // Print is based on a record
        // Tote-shipping gives a Whse. Shipment Line record
        // We will instead use the Item record, as the source of our Item label
        Item.Get(_WhseShipmentLine."Item No.");

        // -- Print
        // Init printer parameters
        Evaluate(TempPrintParameter.Printer, _RequestValues.GetValue('Printer'));
        TempPrintParameter."Label-Template Name" := 'Item Label 3x2';

        // Set print parameters

        // Perform cloud print
        if MobPrint.Run(TempPrintParameterthen begin

            // Command is returned from cloud

            // Convert the printer selected to an Address
            MobPrint.GetPrinterFromName(MobPrinter, TempPrintParameter.Printer);

            // Save response to be sent in the next Mobile response
            MobPrintBuffer.Add(MobPrinter.Address, PrintCommand);

            _SuccessMessage := _SuccessMessage + ' Item label was printed.';

        end else
            // If failed, append Error to ResultMessage 
            _SuccessMessage := _SuccessMessage + ' ' + MobLanguage.GetMessage('PRINT_FAILED'': ' + GetLastErrorText();