- Created by Johannes Sebastian Nielsen, last modified on Nov 04, 2022
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 32 Next »
Case
Print Label on Planned Posting, i.e. Receive, Pick, Put-away, Ship, Move etc.
Proposed solution
This examples prints on posting of Warehouse Receipt Lines
- 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 posting occurs
Example 1: Post on Posting Warehouse Receipts
Step 1: Add printer steps on posting
In order to determine when, where and what to print, we add a step on posting
Add the following code to create a step on posting.
See also: How-to: Add Header Step
// Step 1: Add Header steps
// In order to determine when, where and what to print, we add a step on posting
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnAddStepsToAnyHeader', '', true, true)]
local procedure OnPostReceivekOrder_OnAddStepsToAnyHeader(var _OrderValues: Record "MOB Common Element"; _RecRef: RecordRef; var _StepsElement: Record "MOB Steps Element")
var
MobPrint: Codeunit "MOB Print";
begin
if (_RecRef.Number() in [DataBase::"Warehouse Receipt Header"]) then begin // This example is limited to Whse. Receipts
// Break when 'Printer' step has been collected to prevent infinite loop
if _OrderValues.HasValue('Printer') then
exit;
_StepsElement.Create_ListStep(1, 'Printer');
_StepsElement.Set_header('Label print');
_StepsElement.Set_listValues(' ;' + MobPrint.GetMobilePrinters('Item Label 3x2', '')); // Allow user to also select a blank printer
_StepsElement.Set_helpLabel('If you want a label, please select a printer.');
end;
end;
Step 2: Handle steps on posting to issue print
// Step 2: Handle Header step and issue print
// We read the collected step (printer)
// Issue a print based on printer, label and the current context (Order Header)
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnPostReceiveOrder_OnAfterPostAnyOrder', '', true, true)]
local procedure MyOnPostReceiveOrder_OnAfterPostAnyOrder(var _OrderValues: Record "MOB Common Element"; _RecRef: RecordRef; var _ResultMessage: Text)
var
MobPrinter: Record "MOB Printer";
TempPrintParameter: Record "MOB Print REST Parameter" temporary;
MobPrint: Codeunit "MOB Print";
MobPrintBuffer: Codeunit "MOB Print Buffer";
PrintCommand: Text;
begin
// Did user select a printer, else exit
if not _OrderValues.HasValue('Printer') then
exit;
// Init printer parameters
Evaluate(TempPrintParameter.Printer, _OrderValues.GetValue('Printer')); // Printer selected
TempPrintParameter."Label-Template Name" := 'Item Label 3x2'; // The label to print - consider making this configurable
MobPrint.SetSourceRecRef(_RecRef);
MobPrint.SetRequestElementsFromOrderValues(_OrderValues);
if MobPrint.Run(TempPrintParameter) then begin
// Print was is returned from cloud
TempPrintParameter.GetResponseContentAsBase64Text(PrintCommand);
MobPrint.GetPrinterFromName(MobPrinter, TempPrintParameter.Printer);
MobPrintBuffer.Add(MobPrinter.Address, PrintCommand);
end else
// If failed, append Error to ResultMessage
_ResultMessage := _ResultMessage + ' Print failed: ' + GetLastErrorText();
end;
Example 2: Post on Posting Warehouse Picks
// Step 1: Add Header steps
// In order to determine when, where and what to print, we add a step on posting
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnPostPickOrder_OnAddStepsToAnyHeader', '', true, true)]
local procedure OnPostPickOrder_OnAddStepsToAnyHeader(var _OrderValues: Record "MOB Common Element"; _RecRef: RecordRef; var _StepsElement: Record "MOB Steps Element")
var
MobPrint: Codeunit "MOB Print";
begin
if (_RecRef.Number() in [DataBase::"Warehouse Activity Header"]) then begin // This example is limited to Whse. Picks
// Break when 'Printer' step has been collected to prevent infinite loop
if _OrderValues.HasValue('Printer') then
exit;
_StepsElement.Create_ListStep(1, 'Printer');
_StepsElement.Set_header('Label print');
_StepsElement.Set_listValues(' ;' + MobPrint.GetMobilePrinters('Item Label 3x2', '')); // Allow user to also select a blank printer
_StepsElement.Set_helpLabel('If you want a label, please select a printer.');
end;
end;
Step 2: Handle steps on posting to issue print
// Step 2: Handle Header step and issue print
// We read the collected step (printer)
// Issue a print based on printer, label and the current context (Order Header)
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Pick", 'OnPostPickOrder_OnAfterPostAnyOrder', '', true, true)]
local procedure MyOnPostPickOrder_OnAfterPostAnyOrder(var _OrderValues: Record "MOB Common Element"; _RecRef: RecordRef; var _ResultMessage: Text)
var
MobPrinter: Record "MOB Printer";
TempPrintParameter: Record "MOB Print REST Parameter" temporary;
MobPrint: Codeunit "MOB Print";
MobPrintBuffer: Codeunit "MOB Print Buffer";
PrintCommand: Text;
begin
// Did user select a printer, else exit
if not _OrderValues.HasValue('Printer') then
exit;
// Init printer parameters
Evaluate(TempPrintParameter.Printer, _OrderValues.GetValue('Printer')); // Printer selected
TempPrintParameter."Label-Template Name" := 'Item Label 3x2'; // The label to print - consider making this configurable
MobPrint.SetSourceRecRef(_RecRef);
MobPrint.SetRequestElementsFromOrderValues(_OrderValues);
if MobPrint.Run(TempPrintParameter) then begin
// Print was is returned from cloud
TempPrintParameter.GetResponseContentAsBase64Text(PrintCommand);
MobPrint.GetPrinterFromName(MobPrinter, TempPrintParameter.Printer);
MobPrintBuffer.Add(MobPrinter.Address, PrintCommand);
end else
// If failed, append Error to ResultMessage
_ResultMessage := _ResultMessage + ' Print failed: ' + GetLastErrorText();
end;
Step 3: Modify print "Dataset" (optional)
- Use this event to modify the automatically generated dataset OnPrintLabel_OnAfterPopulateDataset
- See also Customize Labels
- No labels