Wednesday, October 05, 2016

SSRS EP Report Parameters

This is my first post on Enterprise Portal of AX 2012. There a lot of terms, that i have come across while trying to get this assignment done. I have tried to build my own interpretation of these terms, so would like a disclaimer that some of these might not be entirely correct.

The agenda is to publish a certain report on EP along with accepting the filter parameters.

UserControl: This term is often come across when dealing with EP development. A user control is an equivalent of a Form in AX which can render a presentation layer. The difference being that a user control further needs a sharepoint webpart to be hosted within.

To facilitate creation of these user controls, the EP framework has some templates defined and these can be used to create a user control. The templates can be accessed once the project is selected, followed by click on the project menu -> Add new item


For designing a request form to accept the report parameters, please use the "EP User Control with Form" Template. Also take care to change the name of the control at the time of selecting an item, changing the name later has issues syncing the objects with AOT.

The elements on the user control are picked used a group designed for AX on the toolbar. The group is called dynamics AX (shown below, highlighted in red) 




At this point it is important to understand the different files that are generated as a part of instantiation from the template.
The first file is AFZLeaveDetailsReport.ascx; this file stores the basic structure of the presentation. The ascx file is something like a webpage which has the html markup but not the code.

The second file is the AFZLeaveDetailsReport.ascx.cs; this file contains the control definitions for the different controls used on the page. This is basically where the code and events for the controls are created. The link between the two files is created using a codefile tag in the source file ("AFZLeaveDetailsReport.ascx") also shown below  


The third file is the AFZLeaveDetailsReport.aspx.designer.cs; this file contains the definition for any server controls that are used on the markup file ("AFZLeaveDetailsReport.ascx"). This allows the visual studio to do intellisense in the code behind page based on the controls used on the markup page.

( Note: i wondered why the definitions could not be stored in the markup files itself ; the probable reason is that the markup files being units of html have to follow the html standard/format. But this is just a guess )

Now one can design the layout of the request form. We can use a combination of AX controls and asp controls to create a GUI of our choice. Assuming that this GUI would  be used to accept the values for the parameters of the report in focus; once the parameter values have been gathered on the form these will have to be passed on the report object. I have conceived a design where there would be a command button on the form to trigger the report.

To be able to print SSRS report AX Report Viewer control  (shown below) can be used


Just drag and drop this on the user control to create the required construct. Once the control has been dropped it would create a tag as follows: -




 in the above tag ID and MenuItemName have been manually updated using the property sheet in the GUI. The menu name is the output menu item that has an SSRS report attached to it.

To look for and edit the code behind the Print Report button, double click on it and the editor would automatically open the CodeBehind file ("AFZLeaveDetailsReport") with the right parameters for the button on_click event.



The way to pass parameters is to collect them into an dictionary object with an ID name exactly like the parameter name on the report. ( to get the parameter names in the report, one will have to open the SSRS report in visual studio and copy and names from the parameter node of the report.)

Dictionary parms = new Dictionary();

parms.Add("SPYLeaveDetailDS_FromDate", txtFromDate.text);
parms.Add("SPYLeaveDetailDS_ToDate", txtToDate.text);
parms.Add("SPYLeaveDetailDS_EmployeeList", txtEmpNo.text);

// Add the parameters to the report control 
this.LeaveDetailsReport.AddParameters(parms);



Please note that in EP a report would not render if the DP class for the same is extended from SrsReportDataProviderPreProcess. If you have a pre-process report then please consider changing it to SRSReportDataProviderBase

No comments: