IIn this post I will continue with implementation of Report which gets data form web service. I would like to demonstrate Recursive group functionality of Tablix Report.
In short:
Add field with Parent member
Set Recursive group
Create dataset connecting to Reporting Services We Service according to the SSRS connect to web service. Put Tablix component, Insert tab in Report Builder, Table component and Insert Table option. Using Microsoft Visual Studio with Data Tools, go to Toolbox-bar and drag and drop Tablix component.
Map created dataset to inserted Tablix. Right click above the Tablix and choose Tablix Properties from popup menu.
Picture 1 – Tablix properties
Select dataset from Dataset Name select box.
Picture 2 – Tablix Properties
Firstly, we have to prepare parent member which means parent directory of currently listed item. We will use Path field we get from Web Service.
Go to Report Data pane, Datasets section, right click to get Dataset Properties window. Click on Add button and from popup menu select Calculated Field. New item is added to our dataset, name it Parent and go to the Expression icon.
Picture 3 – Add calculated field
Put pattern mentioned bellow to Expression box. The pattern splits Path field by SPLIT function and because SPLIT function returns array data type we point to the last member of array by other usage of SPLIT function together with Length attribute. It gives us parent directory of current member. This solution is not the best one. For example, when you set same name of two directories, the report may not behave the expected way. There are other ways how to achieve this but for our purposes it is enough.
Now we can get to Report Tablix to change Tablix group from detail to Recursive. Firstly, we group data by child member which is current item of repository (Report or Directory). Group Properties -> Group on Name.
Picture 5 – Group properties
Now in Group Properties pane go to Advanced section and set Recursive parent. Select Parent field from select box.
Picture 6 – Recursive parent
Set Group Properties to Expand/Collapse functionality, hide group by default and set Type TextBox as Toggle item (picture below). You can get more info regarding Expand/Collapse functionality in this Expand collapse groups.
Picture 7 – Expand / Collapse group
When you finish previous steps, you should see report similar on picture bellow. From left to right we can see item Type, Path and current item Name. Expand/Collapse is available in case that item has child members.
IIn most of scenarios I realized projects that report Data Sources connect to MS SQL database or to Analysis Services cubes. But reporting services provide you with possibility to connect to more data source types. In this post I would like to show you how to connect with report to Web Service and visualise data. We do not need to developed Web Service for this sample we will use the Reporting Services Web Service. Let’s suppose that we would like to visualise data in Reporting Services Repository.
It can be implemented in few ways. We can use for this task Reporting Services database for example but for our purposes we will use Reporting Services Web Service.
Goal
Create dataset returning data regarding Reporting Services Report Manager directories and reports.
Open Report Builder and create new file or Microsoft Visual Studio with Data Tools, create new project and add new Reporting Services report.
Go to Report Data pane, Data Sources section, right click and select Add Data Source.
Picture 1 – Add Data Source
When Data Source Properties window appears, choose XML in Select connection type select box.
Picture 2 – Connection Type
In Data Source Properties dialog box put Connection string with URL address of your Reporting Services Web Service Endpoint. In my case I will use ReportService2005.asmx.
Picture 3 – Data Source Properties
Create New dataset, select your created Data source DataSource1.
If we look at the code above, we can see that we need to specify method name and its parameters. Everything you need you can find you put URL of We Service Endpoint to your browser. There you can find all methods the web service supports. The code mentioned above is syntax used for Report XML Data Sources. Find more info on the web https://bit.ly/2XvdCWB.
In our case we use Listchildren method which expects two parameters. Item – parent item, the method starts to list, and Recursive specifying you would like to list all its parents recursively. Dataset Properties pane should look like on picture bellow.
Picture 5 – Add Dataset Properties
Voila and we can see items in our dataset. You can link the dataset with the Tablix of your report. As you can see web service gives us information regarding Name and Path of a report or when and by whom was the report created or modified.
Picture 6 – Dataset Fields
In next post I will implement recursive Tablix report with the dataset created in this post. Stay tuned.
In one of previous post I wrote about expand, collapse groups and how useful feature for Tablix component it is. User can expand data of each individual group member to its detail. But in case user would like to expand all group members, the solution becomes inconvenient for fast work with reporting. User must go and click on each member of group to expand data. In case that child groups are set to have the same toggle functionality, collapsed by default, it could become a nightmare for user to work with such a report. Fortunately, you can use parameters to handle Expand/Collapse state of groups. In this post I will show you approach I use in my projects.
Steps in short:
Define report parameter with member correspondent to groups in Tablix
Define report variables connected to the parameter and returning true or false for visibility of each groups
Set group visibility property based on expression
Set toggle item default state based on expression
Create report parameter first. Let’s name it Level, as group level user would like to expand. Go to Parameters Pane, right click above Parameters item and click Add new parameter. In Report Parameter Properties dialog set name and Integer as Parameter Type in general tab. Then go to Available Values tab and set Specify values checkbox – type values user can select. I set values that mean group levels – for our report: Region, Province, Name with values from 0 to 2. The Integer values mean level of group hierarchy. You will see their usage later in this post.
As default values type 0 to choose Region group level by default. It means that our report will be Collapsed by default.
Picture 3 – Report Parameters, Specify values
Right click in Report Builder design surface near to the Tablix component and select Report Properties from popup. Then go to Variables tab and Add 3 variables corresponding to parameter values I set in previous step: Region, Province, Name. I would prefer to use variables that it can be easily manageable on one place, but solution could be implemented directly through expressions. Furthermore, solution with variables could help performance of the report rendering too (see in next posts). To Value items set to them expression which returns true or false value, based on level returned from selected parameter Level. This means when user selects parameter value, these variables calculate visibility for correspondent group.
Picture 4 – Report Properties Variables
Here are expressions you put to variable values:
Region
=IIF(Parameters!Level.Value<=0,true,false)
=IIF(Parameters!Level.Value<=0,true,false)
=IIF(Parameters!Level.Value<=0,true,false)
Province
=IIF(Parameters!Level.Value<=1,true,false)
=IIF(Parameters!Level.Value<=1,true,false)
=IIF(Parameters!Level.Value<=1,true,false)
Name
=IIF(Parameters!Level.Value<=2,true,false)
=IIF(Parameters!Level.Value<=2,true,false)
=IIF(Parameters!Level.Value<=2,true,false)
On picture bellow there are defined each variables.
Picture 5 – Report Properties, Variables
To define expression for each variable, click on expression icon on the right side of input box for Variable and define expression.
Now we set visibility for each group. Because EnglishCountryRegionName name group is default group, it will be visible when user runs report by default. We set Visibility setting for this group to Show. Go to the next group, StateProvinceName group, click to its group area, and set Region variable value to the group visibility property. You can get it by two ways:
Right click on the group StateProvinceName name in the Grouping pane, Visibility section and Show or hide based on expression.
Or you can do it directly in the Properties Pane. When you click on the group in Grouping pane, Hidden property on Properties Pane and set expression value Variables!Region.Value.
Picture 7 – Group Properties, Visibility
I set Region variable value to Show or hide based on expression of StateProvinceName group.
Picture 8 – Show or Hide based on expression
Let’s go to the Level parameter and choose the Region value. On the picture bellow you can see that all groups that are under the Region group in the hierarchy, are expanded. Now you can do the same steps for LastName group.
But there is one thing which should be resolved. Look at picture bellow at Expand/Collapse mark which is set to +. But the state of the group is expanded. Follow next steps to fix it.
Picture 9 – Sales Report
On the picture bellow there is highlighted to which toggle items put bellow mentioned expressions in the Tablix. Each toggle item has its own InitialToggleState since it is standard report item.
Picture 10 – Toggle Items in Report Tablix
For the StateProvinceName group, there was set EnglishCountryRegionName Textbox as toggle item. (it was described in post Expand collapse groups) Click on EnglishCountryRegionName textbox, Go to Properties Pane, Visibility section and set to InitialToggleState expression =CBool(1+CInt(Variables!Region.Value)).
Picture 11 – InitialToggleState, Expression
After confirmation you should see the same in Properties Pane of EnglishCountryRegionName textbox, as on picture bellow.
Picture 12 – InitialToggleState
Now you should see fixed Expand/Collapse mark on picture bellow.
Picture 13 – Sales Report, Expand
Do the same steps for LastName group on StateProvinceName textbox with following expression =CBool(1+CInt(Variables!Province.Value)). On LastName textbox we do not need to set expression, since it is not toggle item of any groups.
Let’s try report now, change Level parameter values. See pictures bellow how report layout changes.