[SSRS] Split invoice lines into separate reports

I had the requirement from a customer to split certain lines into a separate report when printing an sales invoice.

This requirement was new to me and I found it very interesting so I want to share my experience and my solution for this with you.


First the process of printing a report has to be analysed.
When debugging the whole process, the following hierarchy becomes visible:

  • \Classes\SalesInvoiceController\runPrintMgmt
  • \Classes\SrsPrintMgmtController\outputReports
  • \Classes\SrsReportRunService\preRunReport
  • ...
  • \Classes\SrsReportRunRdpPreProcessStrategy\execute
    in Line 27 the processReport method of the DataProvider is called.

The right point to place own code

For me the following point seems the right place to get started:
A new parameter should be added to the contract.
Now we can grab the contract here and run the outputReports() method twice. First run with parameter true and second run with parameter false. In case we can't grab the DataContract, we want to leave the default behavior.
The whole code here can look like this:
Modification in \Classes\SalesInvoiceController\runPrintMgmt
Important is to reset the PrintMgmtReportRun instance so the PrintSettings loop later will print all reports and not only the first!
Then in the DataProvider class we can check the new parameter of the contract and only include the lines that fit the conditions.
First add a new method to class \Classes\SalesInvoiceDPBase that checks the condition to include the line and returns a boolean:
New method to decide include the line
Now the method can be called in the loop of method createData and only proceed if the conditions fit:
call new method in createData
Recognize that we call continue if the conditions doesn't fit instead of wrapping the subsequent code in an if-statement to make the code short and clear.


The important things to have in mind:

  • Reset PrintSettings loop, otherwise only the first report will be printed.
  • Always build conditions that fail fast and early in the process to keep it clean and fast.