MSBA-341 · Lesson 9 of 12 · 19 min
Reports with SSRS
▶ Video coming soon A video version of this lesson is on the way.
Marisol's weekly list of open casting lines without certificates could have been a simple inquiry form, but she wanted it as a printed document for the Monday supplier quality meeting, laid out the same way every week, with a section per foundry and totals by heat. Cobalt Ridge also needed the heat number to print on the product receipt document that went to the warehouse. Both are jobs for SQL Server Reporting Services, usually shortened to SSRS, which is the reporting technology behind the formatted documents in finance and operations apps.
Where SSRS fits
Finance and operations apps offer several kinds of output. Electronic reporting produces regulated formats and configurable documents, Power BI covers analysis, and Excel and inquiry forms cover ad hoc lists. SSRS produces the formatted, paginated reports that ship with the product: purchase orders, invoices, packing slips, trial balances and hundreds of others. The MB-500 skills outline lists implementing reporting as a smaller area of the exam, and it centres on SSRS reports built from report data providers, report extensions and print management. Desmond reminded Prudence that a new report is often not the best answer; if the users want to filter and sort, a form or Power BI is better. Marisol's request was a genuine fixed-layout document, so SSRS fit.
The report data provider pattern
SSRS reports can get data from queries directly, but most reports in finance and operations apps use a report data provider, abbreviated RDP. An RDP class runs X++ to calculate the report's data and writes it to a temporary table; the report design reads that table as its dataset. This pattern lets developers use the full power of X++, such as calling business logic, joining across companies or computing derived values, before any layout is involved. It also keeps calculations out of the report design, where they are hard to test.
| Element | Purpose | Cobalt Ridge example |
|---|---|---|
| Temporary table | Holds one row per report line; TableType is TempDB for large data | CRCastingCertTmp with vendor, heat, item, quantity and line amount |
| Data contract | Holds report parameters; DataContract attribute | CRCastingCertContract with FromDate and VendorGroup |
| RDP class | Extends SRSReportDataProviderBase and fills the temporary table in processReport | CRCastingCertDP |
| Report | The design in a reporting project; dataset bound to the RDP | CRCastingCertReport with design Report |
| Controller (optional) | Extends SrsReportRunController to set parameters or choose a design | CRCastingCertController |
| Output menu item | Lets users run the report from a menu or form | CRCastingCertReport output menu item |
Building the RDP class
The RDP class is decorated with the SRSReportParameterAttribute, naming its contract, so the framework knows which parameters to show. It overrides processReport, where it reads the contract, queries the data and inserts rows into the temporary table. It also has a method decorated with SRSReportDataSetAttribute that returns the temporary table; this is how the report design discovers the dataset and its fields.
[SRSReportParameterAttribute(classStr(CRCastingCertContract))]
final class CRCastingCertDP extends SRSReportDataProviderBase
{
CRCastingCertTmp castingTmp;
[SRSReportDataSetAttribute(tableStr(CRCastingCertTmp))]
public CRCastingCertTmp getCastingCertTmp()
{
select castingTmp;
return castingTmp;
}
public void processReport()
{
CRCastingCertContract contract = this.parmDataContract() as CRCastingCertContract;
PurchLine purchLine;
PurchTable purchTable;
while select purchLine
where purchLine.CRInspectionRequired == NoYes::Yes
&& purchLine.CRInspectionStatus != CRInspectionStatus::Received
&& purchLine.CRInspectionStatus != CRInspectionStatus::Waived
&& purchLine.DeliveryDate >= contract.parmFromDate()
join purchTable
where purchTable.PurchId == purchLine.PurchId
{
castingTmp.clear();
castingTmp.VendAccount = purchTable.OrderAccount;
castingTmp.HeatNumber = purchLine.CRHeatNumber;
castingTmp.ItemId = purchLine.ItemId;
castingTmp.PurchQty = purchLine.PurchQty;
castingTmp.LineAmount = purchLine.LineAmount;
castingTmp.insert();
}
}
}Prudence asked why the temporary table type mattered. A table of type TempDB lives in the SQL database for the session, so large reports can use set-based operations and joins against it. A table of type InMemory lives in the server's memory and suits small row counts. Microsoft recommends TempDB for most RDP reports, and Desmond's rule was to use it unless a report was guaranteed to be tiny.
The report design
Report designs are created in a reporting project in Visual Studio. The developer adds a report, adds a dataset whose data source type is report data provider and points it at the RDP class, and the dataset's fields appear automatically from the temporary table. Designs can be auto designs, which the framework lays out from the dataset with little effort, or precision designs, which are laid out exactly using the report designer and are used for documents like purchase orders. CRCastingCertReport used a precision design with a group per vendor, a table of lines, subtotals by heat and a company header shared with other Cobalt Ridge reports.
Labels in a report design should come from the label file, just like labels in forms, so the report prints in the user's language. Cobalt Ridge's French-speaking users saw the report in French because every caption referred to @CRCustom labels. After designing, the developer deploys the report to the reporting server, which in a developer environment happens from Visual Studio and in sandbox and production happens as part of the package deployment.
Controllers and parameters
Many reports work without a custom controller; the output menu item can point straight at the report and the framework builds a dialog from the contract. A controller extending SrsReportRunController is needed when the report must set parameters from the caller, such as using the selected vendor when the report is run from the vendor form, or choose between designs at run time. The controller's prePromptModifyContract method is the usual place to fill contract values before the dialog appears. A UI builder for reports, extending SrsReportDataContractUIBuilder, plays the same role as in SysOperation: lookups and dialog behaviour.
Extending a standard report
The second request was the heat number on the product receipt document. That report belongs to Microsoft and cannot be overlayered. The extension approach has three parts. First, the data must reach the report's temporary table, so the developer adds the field to the temporary table through a table extension. Second, something must fill the field. The standard RDP class is extended with Chain of Command, usually wrapping the method that inserts each line or processReport itself, or a post-handler on a method that fills each row, depending on what the standard class exposes. Third, the design must show the field. Standard designs are changed by creating a report extension or, for designs that are not extensible in that way, by duplicating the standard design into the extension model and registering the copy through print management.
[ExtensionOf(classStr(PurchPackingSlipDP))]
final class PurchPackingSlipDP_CRInspection_Extension
{
// Wrap the standard method that fills each line of the report's temporary table.
// Check the reference metadata for the exact method name and signature
// before writing the wrapper; this sketch shows the shape only.
protected void insertIntoPurchPackingSlipDetailsTmp()
{
next insertIntoPurchPackingSlipDetailsTmp();
// Copy CRHeatNumber from the receipt line to the temporary table here.
}
}Print management
Documents such as purchase orders and product receipts are printed through print management, which lets administrators choose a report format per document and per company, set the number of copies and the destination. When an extension provides a new design for a standard document, the design is registered so it appears as a choice in print management. The standard pattern is to subscribe to the delegate on the PrintMgmtDocType class that supplies the default report format and return the new design for the relevant document type; administrators can then choose the new format in the print management setup.
Desmond liked this approach because it kept the standard design available. If the new receipt design had a problem, Annelise could switch print management back to the standard format without a deployment. He also pointed out that every duplicated design is a maintenance cost: when Microsoft changes the standard design in a later version, the copy does not receive the change. Lesson 11 returns to that problem.
Testing reports
Report testing has two halves. The data half is tested like any other X++ code: call the RDP's processReport with a contract and inspect the temporary table, which can be automated with a test class. The layout half is tested by running the report to screen and to PDF with realistic data, including long names, many lines, French captions and multiple pages, and checking page breaks and totals. Prudence printed the weekly report for a test week with 140 open lines across six foundries and found that a long foundry name wrapped onto two lines and pushed the group header off the page; she fixed the column width before the Monday meeting saw it.
Multiple designs and parameters
One report can have several designs, for example a summary and a detailed version of the same data. The controller chooses which design to run, usually from a parameter or from the menu item that started the report. In Cobalt Ridge's case, the weekly casting report had a detailed design for the quality meeting and a one-page summary for Thandeka, both reading the same temporary table. The controller set the report name to the design that matched the menu item, and the summary menu item was in the monitor privilege only.
Performance of RDP reports
Reports run against live transactional data, so their queries deserve the same care as any other code. The RDP should select only the fields it needs, use joins and set-based inserts where possible, and filter on indexed fields. For reports that take a long time to fill their temporary tables, the framework supports a preprocessed pattern, in which the data provider extends SrsReportDataProviderPreProcessTempDB so that data processing happens before the rendering step and the user is not left waiting on the report viewer. Prudence measured the weekly report's processReport in the developer environment with a full week of test data and found it took under two seconds, so the simple pattern was enough.
Deploying and checking reports
Report deployment is a step that is easy to forget. A developer who changes a report design and deploys only the model may find the old design still rendering, because the report itself was not redeployed to the reporting service. In the developer environment, Visual Studio offers report deployment as part of the deploy options; in sandbox and production, the package deployment handles it. After every deployment Annelise ran each changed report once to screen, which took a minute and avoided surprises on Monday morning.
When electronic reporting fits better
Some documents in finance and operations apps can also be produced with electronic reporting, through the business document management feature, which lets business users edit document templates in Word or Excel without a developer. Desmond mentioned this because a future request to change the receipt document's layout might be better handled there than by another SSRS design. For the inspection feature, the weekly report needed calculations and grouping that suited an RDP, and the receipt change was small, so SSRS remained the choice.
Reports and security
Every report needs an output menu item, and every output menu item needs to be in a privilege, or users will not be able to run the report. The RDP class runs under the user's identity, so the data it reads is also subject to the user's security, including any extensible data security policies on the tables it queries. Prudence tested the weekly report as a user with the monitor duty only and confirmed it ran and showed all three companies' lines when run from the cross-company menu item, and only the current company's lines otherwise. That behaviour came from the RDP's query, which used crossCompany only when the contract asked for it, and the report's dialog showed that option only to users with the controller role.
Worked problem
Totals that do not add up
During testing, the total line amount on the weekly report is higher than the sum of the open lines Marisol checks in the form. What is the likely cause?
Show solution
- Look at the RDP query: it joins PurchLine to PurchTable on PurchId.
- Check whether any other join could multiply rows. A version of the query that also joined to the delivery schedule lines would produce one row per schedule line.
- Look at the temporary table: if it contains duplicate rows for one purchase line, the join is the cause.
- Fix the query so each purchase line produces one row, and add a test that compares the temporary table row count to the count of matching purchase lines.
Answer: Totals in RDP reports are only as good as the query; a join that multiplies rows inflates every sum. Testing the temporary table catches it before the layout does.
Common mistakes
MistakeDoing calculations in report expressions.
InsteadCalculate in the RDP class, where X++ can be tested, and keep the design for layout.
MistakeUsing an InMemory temporary table for a large report.
InsteadUse TempDB for most RDP reports.
MistakeDuplicating a standard design without registering it in print management.
InsteadRegister the new design so administrators can choose it and switch back.
MistakeHard-coding captions in the design.
InsteadUse labels so reports print in each user's language.
Summary and key terms
- SSRS produces formatted, paginated documents; forms, Excel and Power BI are better for analysis and ad hoc lists.
- The RDP pattern computes data in X++ into a temporary table that the report design reads.
- RDP classes use SRSReportParameterAttribute for the contract and SRSReportDataSetAttribute for the dataset.
- Controllers set parameters from the caller or pick designs; UI builders shape the dialog.
- Standard reports are extended through table and class extensions plus report extensions or registered copies in print management.
- SSRS
- SQL Server Reporting Services, the engine for paginated reports in finance and operations apps.
- Report data provider (RDP)
- A class that fills a temporary table with report data using X++.
- Precision design
- A report layout designed exactly, used for business documents.
- Auto design
- A report layout generated from the dataset with little manual design.
- Print management
- Setup that chooses report formats, copies and destinations for business documents.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why did Marisol's request suit SSRS rather than a form?
Show answer
She needed a fixed, printed layout every week, not a filterable list.
Which method of the RDP class fills the temporary table?
Show answer
processReport.
How can administrators go back to the standard receipt design if the new one has a problem?
Show answer
Change the report format in print management; no deployment is needed.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.