How to Change Print Destination Settings Dynamically

Report print destination settings of an executing report are set using the report dialog form, e.g. by using Print Management Setup for reports such as Purchase order and Customer Invoice. However, they can also be changed dynamically, i.e. during report execution.

This can be done by injecting custom business logic at the specific point in report execution pipeline, by using a custom Docentric DSP class. This class extends the base Docentric DSP class (DocDataSourceProviderSrsReporting), which is also called Default DSP class, and overrides the overrideReportRunSettings() method.

You can use Visual Studio template of DSP class called DSP Class for Print Destination Placeholders.

In the overrideReportRunSettings() method you can:

  • Add additional attachments to the same email that the generated report is going to be attached to.
  • Change the target print destination under certain conditions, e.g. from Screen to File.
  • Change the target print destination settings, e.g. change report execution context record from Purchase confirmation (VendPurchOrderJour) to Purchase orders (PurchTable). Changing context record affects saving report to Attachments and use of Standard placeholders.
  • Change the selected template (aka design), e.g. if you want to use a specific template of Customer invoice under special conditions that cannot be set in Print Management Setup.
  • Handle custom placeholders. Learn how >>
In order to set up a report to use a custom DSP class with the overridden overrideReportRunSettings() method, you have to add this report to Docentric report setup first. Next, you need to select this new custom DSP class to be used for the report instead of the Default DSP class. See how >>
If you are using Docentric AX Free Edition, you can also extend the base Docentric DSP class, override the overrideReportRunSettings() method and change dynamically report print destination settings.

Let’s take a look at some examples.

Add additional email attachments and change the selected template

Sometimes we want to email report (e.g. Customer invoice) with some additional attachments (e.g. Terms and Conditions document). We can easily achieve that in the overrideReportRunSettings() method, by fetching these additional documents from Attachments, SharePoint, Azure blob storage or our custom setup.

Also, imagine that you want to have a watermark ‘COPY’ in the Copy document of Purchase order. Let’s say that you have created a custom report design (template) with such watermark. To force the correct template selection without using Print Management Setup, you can dynamically change the selected template in the overrideReportRunSettings() method as shown below.

From ver. 3.3.4 we have UI for this functionality, see Report Attachments How-To Manual

Change report execution context record when saving report to Attachments

Take a look on how we can achieve, instead of attaching the Purchase order report to the VendPurchOrderJour table (displayed on the Purchase order confirmations form), to attach the report to the PurchTable table (displayed on the Purchase orders list page or the Purchase order form), or even to the VendTable table (displayed on the Vendors list page or the Vendor form):

Read more about Saving to Attachments in the blog article >>

See also

How to Use the New Memory Print Destination >>
How to Run an SSRS Report from Code >>
How to Use Custom Placeholders in Print Destinations >>

IN THIS ARTICLE