Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Info | ||
---|---|---|
| ||
Extension version MOB5.23 |
Case
Excerpt |
---|
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::Codeunit, Codeunit::"MOB WMS Adhoc Registr.", 'OnGetRegistrationConfiguration_OnAddSteps', '', true, true)]
local procedure MyOnGetRegistrationConfiguration_OnAddSteps(_RegistrationType: Text; var _HeaderFieldValues: Record "MOB NS Request Element"; var _Steps: Record "MOB Steps Element"; var _RegistrationTypeTracking: Text)
var
MobWmsToolbox: Codeunit "MOB WMS Toolbox";
MobPrint: Codeunit "MOB Print";
begin
// Verify this should only affects Tote-shipping
if _RegistrationType <> MobWmsToolbox."CONST::ToteShipping"() then
exit;
_Steps.Create_ListStep_Printer(2, 'Printer');
_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.');
_Steps.Set_optional(true);
end;
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::Codeunit, Codeunit::"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)
var
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;
begin
// Verify this should only affects Tote-shipping
if _RequestValues.GetValue('RegistrationType') <> MobWmsToolbox."CONST::ToteShipping"() then
exit;
// -- Prepare to Print
// Did user select a printer?
if _RequestValues.GetValue('Printer') = ' ' then
exit;
// 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.");
RecRef.GetTable(Item);
// -- Print
// Init printer parameters
Evaluate(TempPrintParameter.Printer, _RequestValues.GetValue('Printer'));
TempPrintParameter."Label-Template Name" := 'Item Label 3x2';
// Set print parameters
MobPrint.SetSourceRecRef(RecRef);
MobPrint.SetRequestElements(_RequestValues);
// Perform cloud print
if MobPrint.Run(TempPrintParameter) then begin
// Command is returned from cloud
TempPrintParameter.GetResponseContentAsBase64Text(PrintCommand);
// 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();
end;