How-to: Print label to specific printer (Report Print)

How-to: Print label to specific printer (Report Print)

Description

Printing a Mobile Item Label from AL code, in a situation where all the values are known.

Use case

If you as part of a process wish to print an Mobile Item Label to a specific printer.

The same approach can be used to print Mobile License Plate labels and Mobile License Plate Content labels.

In the example below, we will print a label as part of the production output.

 

Print an Item Label as part of posting of Production Output

// Example of how to print an item label from code when a production output is being posted [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Adhoc Registr.", 'OnPostAdhocRegistrationOnProdOutput_OnAfterCreateProductionJnlLine', '', false, false)] local procedure PrintItemLabel_OnPostAdhocRegistrationOnProdOutput_OnAfterCreateProductionJnlLine(var _RequestValues: Record "MOB NS Request Element"; var _ProductionJnlLine: Record "Item Journal Line") var Item: Record Item; MobItemLabel: Report "MOB Item Label"; PrinterSelection: Record "Printer Selection"; DesigntimeReportSelection: Codeunit "Design-time Report Selection"; MobForcePrinterSelection: Codeunit "MOB Force Printer Selection"; begin // Set filters on the DataItem Item.SetRange("No.", _ProductionJnlLine."Item No."); MobItemLabel.SetTableView(Item); // Set global variables on the request page of the report MobItemLabel.Set_VariantCode(_ProductionJnlLine."Variant Code"); MobItemLabel.Set_Quantity(1); // Assuming we want to print GS1 barcodes with qty=1 per label - see NoOfCopies below MobItemLabel.Set_UoM(_ProductionJnlLine."Unit of Measure Code"); MobItemLabel.Set_LotNo(_ProductionJnlLine."Lot No."); MobItemLabel.Set_ExpirationDate(_ProductionJnlLine."Expiration Date"); MobItemLabel.Set_SerialNo(_ProductionJnlLine."Serial No."); MobItemLabel.Set_PackageNo(_ProductionJnlLine."Package No."); MobItemLabel.Set_NoOfCopies(Round(_ProductionJnlLine.Quantity - 1, 1, '>')); // Results in a label per produced unit, as it prints 1 plus the number of copies (1 original + n copies) // Set the printer for the report to overrule the default printer selection. PrinterSelection.FindFirst(); // Replace with your logic to select the correct printer MobForcePrinterSelection.Set_ForcedPrinterSelectionForCurrentSession(Report::"MOB Item Label", PrinterSelection."Printer Name"); // Set layout for the report to overrule the default report layout. DesigntimeReportSelection.SetSelectedLayout('Item Label 3x2', 'a5727ce6-368c-49e2-84cb-1a6052f0551c'); // App Id for Tasklet Mobile WMS //DesigntimeReportSelection.SetSelectedLayout('My Item Label 3x2'); // Use this syntax if you have created a custom layout directly in the tenant // Run the report MobItemLabel.UseRequestPage := false; MobItemLabel.RunModal(); // Clear the forced printer selection (stored in a Single Instance Codeunit) MobForcePrinterSelection.Clear_ForcedPrinterSelectionForCurrentSession(); // Clear the selected layout after printing (stored in a Single Instance Codeunit) // (Implementation differs per BC version. Pick the correct one for your BC version) DesigntimeReportSelection.ClearLayoutSelection(); end;

 

Version History

Version

Changes

Version

Changes

MOB5.57

Introduced

See also