When a report is printed to a network printer in Dynamics 365 for Finance and Operations, it is first generated as a collection of EMF images, i.e. pages and stored in Azure Blob storage. Print job settings are stored together with the printing pages. A record is inserted in the Document routing status table in D365FO, with the Pending status, representing the print job. This table acts as a printing queue.
A Document Routing Agent (DRA) app queries D365FO (Document routing status) using OData for the pending print jobs, addressed to those network printers that it is responsible for. DRA queries D365FO at certain frequency, which is by default configured to 5 seconds.
The print job from Document routing status gives the information to DRA, where to download the document pages and print settings from. The document is downloaded by DRA and spooled to the target network printer. The corresponding Document routing status record (i.e. the print job) is updated first with the Processing status, and afterwards to Succeeded or Failed. If the record is marked as Succeeded, the printing document and settings are deleted from Azure Blob storage.
Note that the status Succeeded only means that DRA has successfully created the print job and sent it to the Windows Print Spooler.
DRA printing delay
Now when we know how DRA works, we can discuss printing delays you might have been experiencing when printing documents from D365FO via DRA.
Let’s say that you have many printers and high-volume print jobs on a regular basis.
The question is, what we can do to reduce this delay?
Solution #1: Install multiple DRA clients
You can install and run multiple DRAs to increase the number of concurrent printing operations. Thus, you will have multiple polling DRAs and reduce the overall printing delay time.
DRA can run in two modes: as a desktop application and as a Windows service. If you want to run multiple DRAs on a single machine, for desktop app it suffices to start it as many times as you need running instances. On the other hand, if you want multiple DRA services up and running, this can be done by using the SC.exe (Service Control) tool, which enables you to create, start, stop, query or delete any Windows service.
Install multiple instances of the DRA Service on a single machine
We prepared two scripts you can download here, which enables you to create multiple instances of the DRA service and likewise, to delete an instance of the DRA service. The scripts are based on the SC.exe tool.
By running the InstallDRAService.cmd script, you will be able install a new instance of the DRA Service (C:\Program Files (x86)\Microsoft Dynamics 365 for Operations - Document Routing\Microsoft.Dynamics.AX.Framework.DocumentRouting.Service.exe), under the name and description you enter.
Solution #2: Increase DRA polling frequency
You can configure DRA to poll D365FO every second instead of every 5 seconds for a new document to print. This can be done by utilizing a hidden configuration option in the DRA configuration file.
Step 1: Locate the DRA config file
The file is called Microsoft.Dynamics.AX.Framework.DocumentRouting.config and it is located in C:\ProgramData\Microsoft\Microsoft Dynamics 365 for Operations – Document Routing\.
Step 2: Add the new settings for configuring the DRA polling rate
The new setting should be in the form:
<add key="ida:DocumentRoutingTimerNumSeconds" value="X" />
The value for the DRA polling interval can be as low as 1, meaning that DRA will poll every second.
What else does a DRA config file contain
In the Microsoft.Dynamics.AX.Framework.DocumentRouting.config file we can add settings which don’t exist in the initial configuration file, which is created during the installation, please see below.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ida:AADInstance" value="https://login.microsoftonline.com" />
<add key="ida:ApplicationId" value="GUID" />
<add key="ida:Tenant" value="Tenant Name" />
<add key="ida:AXResourceId" value="The D365FO Root Url" />
<!-- Defines if the print jobs are handeled by Document Routing Agent or Service -->
<add key="ida:RunAsWindowsService" value="True or False" />
<!-- Enable or Disable Log Viewing form in Document Routing Agent -->
<add key="ida:EnableInAppLoggingView" value="True or False" />
<!-- Default is the maximum number of items displayed in DRA log (50.000) -->
<add key="ida:MaxCountOfEventLogsOnLoggingView" value="50000" />
<!-- This setting is ignored by DRA -->
<add key="ida:AutoUnregisterDisconnectedPrinters" value="Not Available" />
<add key="ida:WindowsServicePdfTargetFolder" value="Target folder for PDF Routing" />
<add key="ida:IsDirectPdfPrintingSupported" value="True or False" />
<!-- The polling interval for new print jobs -->
<!-- Default is 5 seconds, if not configured -->
<add key="ida:DocumentRoutingTimerNumSeconds" value="5" />
</appSettings>
</configuration>
Note that the settings ignored by DRA are configured from within D365FO, in the Client application (DocumentRoutingClientAppEntity) data entity, which is invoked by DRA. You can also examine this data entity to better understand how DRA works and what are its responsibilities.
For example, these are the settings of a newly installed DRA in our environment.
<?xml version="1.0" encoding="us-ascii"?>
<configuration>
<appSettings>
<add key="ida:AADInstance" value="https://login.microsoftonline.com" />
<add key="ida:ApplicationId" value="8187df2a-0661-4f3d-9866-3b06e2703b79" />
<add key="ida:Tenant" value="docentric.com" />
<add key="ida:AXResourceId" value="https://usnconeboxax1aos.cloud.onebox.dynamics.com" />
<add key="ida:RunAsWindowsService" value="False" />
<add key="ida:EnableInAppLoggingView" value="True" />
<add key="ida:WindowsServicePdfTargetFolder" value="C:\ProgramData\Microsoft\Microsoft Dynamics 365 for Operations - Document Routing\PdfFiles" />
</appSettings>
</configuration>
The cons
By reducing the DRA polling interval, DRA will now call OData (the DocumentRoutingClientAppEntity data entity) for querying D365FO (reading and updating the Document routing status table) each second instead of each 5 seconds. Consequently, a DB connection will be initiated for every DRA polling event and this might cause performance issues. The same applies if you install and run multiple DRA clients. Thus, these techniques should be used only if you really need to reduce printing latency.
Improve DRA robustness: Configure one DRA per printer
Some D365FO users also use a technique to configure one DRA per network printer. This way, if a print job for a particular printer blocks DRA (for example, the printer became inaccessible), the rest of the pending print jobs which target other printers will not be blocked, and printing to other printers will work normally.
At high volume printing with several parallel DRA instances on one VM you can experience the conflict while writing logs. The log folder path is hardcoded and all instances write to the same log files. DRA has some error handling, but in some cases it can still crash.
System.IO.IOException: The process cannot access the file ‘C:\ProgramData\Microsoft\Microsoft Dynamics 365 for Operations – Document Routing\Logs\Admin_2022_11_29.log’ because it is being used by another process.
Disabling “Enable logging view in application” has solved (or at least mitigated) the issue.
I found this article very insightful and helpful.
When attempting to install/run multiple instances of the DRA on one VM is proving more difficult than expected.
Simply launching the DRA application multiple times does not work as expected. Yes, X amount of instances open but they do not operate independent of one another. Whatever setting/printer that’s enabled on one is reflected on the other.
I require multiple independent DRA agent’s on one machine where different printers can be registered on each. The goal of this requirement/test is to confirm if it can reduce the bottlenecks caused by high volume printing with hundreds of printers.
Hello Corne,
Launching multiple DRA services or applications will speed up the printing process. However, you cannot use a different printer setup for each instance because DRA uses settings from the same file system location.