A Reporting Services report generally exposes content to end-users but some interactivity can be provided by embedding asp pages to write to the reporting back-end. While for complex user interaction where user input is required (e.g. comments) asp pages is the only way to go, there is another area of simple functionality (in example):
- saving default values for selected parameters
- locking of functionality by a power user
- deleting data from a fact table
or in general – if users do not need to enter any input, but rather trigger some action in the back-end, we can use stored procedures without writing any .NET code.
As an example, we will save a selected Business Unit from a parameter drop-down box to a database table which is used to derive the default value for that parameter. As different users may be interested in different Business Units, we will store not only the default parameter value but the user name as well.
Firstly, let’s assume that we have already created a report called “Balance Sheet”, which has two parameters – Business_Unit and Period. To keep the case simple, I will assume that the parameter is driven by a stored procedure in a relational back-end.
We first need a place to store the default parameter values – we can simply create a Ctl_User Preference table:
CREATE TABLE Ctl_User_Preferences (
The default parameter value is retrieved from that table by a stored procedure which takes the a User Id as a parameter and returns the Business Unit. Then it is used in the Default Value for the report parameter in Reporting Services.
Now we can investigate the process of populating the table. We place a textbox showing “Save Preferences” text on our Balance Sheet report which links to another report, confirming the user action and writing the selected value of the Business_Unit parameter to the Ctl_User_Preferences table.
We have to create the “confirmation” report first (e.g. “User Preferences Confirmation”). It has to have two parameters – Business_Unit and another, hidden, dummy parameter which we can call Save_Parameter. The Save_Parameter parameter must be able to accept Null values. Then, we create a stored procedure which accepts @User_Name and @Business_Unit parameters and updates or inserts the two values in the Ctl_User_Preferences table. Next we link @Business_Unit to the Business_Unit report parameter and the @User_Name parameter to User!UserID.Value. We link the stored procedure to the hidden parameter by using it for getting its default value (Null as it does not return anything). After completing these steps we end up with a report which “writes” a Business_Unit in the Ctl_User_Preferences table when opened.
To summarise the events flow, when a user clicks on the textbox a new pop-up window containing the confirmation report opens and while rendering it, Reporting Services calls the stored procedure which saves the Business Unit parameter to the Ctl_User_Parameters table. Next time the user opens the Balance Sheet report, the Business Unit parameter will default to the saved value as its default value is retrieved from the Ctl table.
We can also use this technique to lock/unlock certain functionality, such as changing the reporting period, or even deleting data in our fact tables by placing links in a table or a matrix next to measures and passing their coordinates to the “confirmation” report.
This out of the box functionality in Reporting services can be quite powerful for all sorts of quick tweaks to our reports with comparatively small development effort, thus being quite worthwhile implementing.