How-to: Do not collect printer name (Report Print)

How-to: Do not collect printer name (Report Print)

Description

Skip collecting printer name when printing a label

Use case

If you can determine the printer based on label name, context, user name, etc. then you may skip collecting printer-step 

 

Modify the printer step

We hide the step and we set a default value.

This way, the value is set, but the user will not be prompted.

Using event OnLookupOnPrintReport_OnAfterAddStepForReport

 

    // [Example] Hide printer step, instead of collecting the value, set a (hidden) default value

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB Report Print Lookup", 'OnLookupOnPrintReport_OnAfterAddStepForReport', '', true, true)]

    local procedure MyOnLookupOnPrintReport_OnAfterAddStepForReport(_MobReport: Record "MOB Report"; var _RequestValues: Record "MOB NS Request Element"; _SourceRecRef: RecordRef; var _Step: Record "MOB Steps Element");

    var

        MobReportPrinter: Record "MOB Report Printer";

    begin

        // Making sure we only handle relevant label templates

        if not _MobReport."Display Name".Contains('3x2') then

            exit;

 

        // Making sure we only handle the relevant step

        if _Step.Get_name() <> 'ReportPrinter' then

            exit;

 

        // Find the printer to use

        MobReportPrinter.FindFirst();

 

        // Set defaultValue and hide printer-step

        _Step.Set_defaultValue(MobReportPrinter."Printer Name");

        _Step.Set_visible(false);

    end;

See also