web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

Server Side Printers: some new (good) things to know

(0) ShareShare
ReportReport
Posted on by

Starting from April 2021 Cumulative Updates (CU), Microsoft Dynamics 365 Business Central 14.x and onward versions are now implementing server side an internal check to exclude the most common file printers such as Microsoft Print to PDF, XPS writer and Fax.

This is needed since typically these file printers do have a UI object that would request for path when called. This is not allowed server side.

Below the relevant TFS entry from e.g. version 14.x Knowledge Base article

Cumulative Update 23 for Microsoft Dynamics 365 Business Central April'19 on-premises (Application Build 14.24.46857, Platform Build 14.0.46844)

387122

Background tasks from job queue entries run infinitely and remain in process when you print file outputs such as XPS or PDF.

 

Why this could be important for your on-premises deployment?

Because if you have background sessions that perform some printing jobs these could wait forever waiting for a response from a printer that do have a file output (such as PDF or XPS ones).

 

Excluding these special printer server side from the server selection it will help in avoiding saturation of endless background session server side.

This issue, then, will never appear from April 2021 CU onwards.

 

This is not ended.

What about versions still in previous Cumulative Updates and other file printers that might be added server side?

From an application perspective, this was already uptake with Codeunit 9655 Init. Server Printer Table

Looking at the core procedure, behind the scenes, the application will populate a subset of server side printers with only the ones that do have maximumcopies > 1 and discarding all others

…

OnRun(VAR Rec : Record Printer)

  InitTempPrinter(Rec);

 

InitTempPrinter(VAR Printer : Record Printer)

  PrinterSettings := PrinterSettings.PrinterSettings;

  PrinterSettingsCollection := PrinterSettings.InstalledPrinters;

  FOR i := 0 TO PrinterSettingsCollection.Count - 1 DO BEGIN

    PrinterName := PrinterSettingsCollection.Item(i);

    PrinterSettings.PrinterName := PrinterName;

    Printer.ID := COPYSTR(PrinterName,1,MAXSTRLEN(Printer.ID));

    IF PrinterSettings.MaximumCopies > 1 THEN

      Printer.INSERT;

  END;

…

 

How can you see this codeunit in action?

Create or change a Job Queue Entry record to use Report and select the Printer Name dropdown. There you go! There is no Microsoft Print To PDF nor XPS nor Fax shown in there because of the aforementioned codeunit check.

 

For previous versions and CUs, then, you might think of subscribing to an event in the ReportManagement codeunit and check if the current client type is a background session and also not a processing only report to achieve a similar results that you have through platform since April 2021 CUs.

 

Below a simple code snippet to get you inspired

 

codeunit 50100 MyCodeunit

{

    [EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterGetPrinterName', '', true, true)]

    procedure OnAfterGetPrinterName(ReportID: Integer; var PrinterName: Text[250]; PrinterSelection: Record 78);

    var

      DotNetPrinterSettings : dotnet PrinterSettings; 

      DefaultPrinterName : Text;

      InitServerPrinterTable : Codeunit "Init. Server Printer Table";

    begin

      //Check if printing through a background session and do have a layout to print

      if (CurrentClientType = ClientType::Background) and 

         (Report.DefaultLayout(ReportID) <> DefaultLayout::None) then begin

            //If PrinterName is not set, it means no PrinterSelection record hence default to server side default printer

            if PrinterName <> '' then begin

                DotNetPrinterSettings := DotNetPrinterSettings.PrinterSettings;

                DefaultPrinterName := DotNetPrinterSettings.PrinterName;

            end;

            //Check if the printername is a valid printer name for server side printing otherwise it errors

            InitServerPrinterTable.ValidatePrinterName(DefaultPrinterName);

         end;

    end;

}

 

dotnet

{

    assembly("System.Drawing")

    {

        Version = '4.0.0.0';

        Culture = 'neutral';

        PublicKeyToken = 'b03f5f7f11d50a3a';

        type("System.Drawing.Printing.PrinterSettings"; "PrinterSettings")

        {

        }

    }

}

I have the same question (1)
  • Andy Sather Profile Picture
    on at

    Thank you Duilio

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,703

#2
YUN ZHU Profile Picture

YUN ZHU 803 Super User 2025 Season 2

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 750 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans