How to Dynamically Switch Selected Template

When a Docentric SSRS or Basic report is printed to a selected print destination Docentric AX Framework needs to know which template to use in order to execute the report, since each report can have more than one template (e.g. for different companies and languages).

In case of an SSRS report the selected template is always the report default template whereas for a Basic report, any of the report templates can be selected on the report dialog form.

However we can change a selected report template and language dynamically, i.e. during report execution. To do so, we need to inject custom business logic at the specific point in the report execution pipeline that 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 a 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 a selected template 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 a 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 >>

We can change most of the executing report settings including a selected template as well. Learn more here about which report execution settings exactly we can affect.

We can access the selected Template ID, Company ID and Language ID (and change them) through the parmTemplateId(), parmTemplateCompanyId() and parmTemplateLanguageId() methods of an DocReportRunContext object which is the input parameter of the overrideReportRunSettings() method.

To clear things up take a look at the sample implementation of the overrideReportRunSettings() method:

In this method we are replacing the currently selected template with the one which has Title set to 'May month template' under the condition that the month of the FromDate report parameter is May.

Take a look at another example. For the Purchase order report we are going to use different templates for Original and Copy of the document.

See also

How to Dynamically Change Print Destination Settings >>
How to Use Placeholders in Print Destination Settings >>
How to Use More Than One Template for a Docentric SSRS Report >>
How to Use More Than One Template for a Docentric Basic Report >>