How to Dynamically Change Print Destination Settings

Print destination settings of an executing Docentric SSRS or Basic report are usually selected by using the report dialog form. They can also be changed dynamically, i.e. during report execution.

To dynamically change report execution settings (e.g. Report Caption, the Save to Archive flag, Selected Print Destination, Selected Template, etc.) we need to inject custom business logic at the specific point in the report execution pipeline.

The report execution pipeline consists of the following steps:

  1. Open the report dialog form (if not running a report from code or in batch or in case of an SSRS Print Management report).
  2. Validate the report parameters and other report settings likewise the selected print destination settings.
  3. Get the run-time report data source, i.e. needed data for printing the report.
  4. Override the report execution settings such as Selected Template, Selected Print Destination, Report Caption, Save to Archive Flag, etc. and replace Print Destination Placeholders, if any.
  5. Generate the report in the requested format and send it to the selected print destination.

To dynamically change selected print destination settings we need to inject custom business logic at the 4th step in the pipeline by extending the overrideReportRunSettings() method of the report DSP (Data Source Provider) class.

Note that in general we don't have to create a custom DSP class for an SSRS report because in many cases using the base DSP class is sufficient. In case you want to dynamically change the execution report settings, replace Print Destination Custom Placeholders or to add additional data to the report data source, you will need to create a custom DSP class using the wizard. Learn how >>

Since we get an instance of the DocReportRunContext class as an input parameter of the overrideReportRunSettings() method, we can affect all executing report settings which are exposed through this class. These are:

  • Report Caption
  • Template ID
  • Company ID for selecting the template
  • Language ID for selecting the template
  • Currently selected print destination
  • Email, File or Printer print destination settings
  • Save to Archive flag
  • Suppress Success Message flag
  • Execute Only Data flag
  • Report Execution Context Record

Take a look at the sample implementation of the overrideReportRunSettings() method:

Another example shows how to change the name by adding VendAccount (a report parameter) as the suffix:

Using the same method and the DocReportRunContext class we can also change the Report Execution Context record. This record is otherwise automatically set through _args.record() of an SSRS controller instance. If we print report to the File print destination and we use the Save to attachments option, the report output file will be attached to the Report Execution Context record. For example, if we run the Purchase order report from the Purchase order confirmations form, the report will be attached to the VendPurchOrderJour table and it will accessible through Attachments on the Purchase order confirmations form or on any other form where this table acts as a master form data source.

Take a look 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

Walkthrough of this Example >>
Download Resources for the Whole Example >>
See More Examples >>