This is a migrated thread and some comments may be shown as answers.

How to set report name and provide a parameter

9 Answers 1166 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 10 Apr 2017, 01:07 PM

By following the instructions on this page: How To: Use HTML5 ASP.NET Report Viewer, I've been able to incorporate a Telerlik sample report into my app.The code it created is below. But now I'd like to have it reference my own Telerik report I've created. The report is in a different project (named MyApp.Reporting) and the name of the report is RentReceipt.cs. The report also takes a single parameter (named ClientID). How can I change the code below to reference my own report and pass it the required parameter?

 

<script type="text/javascript">
        $(document).ready(function () {
            $("#reportViewer1")
                .telerik_ReportViewer({

                    // The URL of the service which will serve reports.
                    // The URL corresponds to the name of the controller class (ReportsController).
                    // For more information on how to configure the service please check http://www.telerik.com/help/reporting/telerik-reporting-rest-conception.html.
serviceUrl: "/api/reports",

                    // The URL for custom report viewer template. The template can be edited -
                    // new functionalities can be added and unneeded ones can be removed.
                    // For more information please check http://www.telerik.com/help/reporting/html5-report-viewer-templates.html.
                    // templateUrl: '/ReportViewer/templates/telerikReportViewerTemplate-11.0.17.222.html',

                    //ReportSource - report description
                    reportSource: {
                        // The report can be set to a report file name (trdx report definition) 
                        // or CLR type name (report class definition).
                        report: "SampleReport.trdp"
                    },

                    // Specifies whether the viewer is in interactive or print preview mode.
                    // PRINT_PREVIEW - Displays the paginated report as if it is printed on paper. Interactivity is not enabled.
                    // INTERACTIVE - Displays the report in its original width and height without paging. Additionally interactivity is enabled.
                    viewMode: telerikReportViewer.ViewModes.INTERACTIVE,

                    // Sets the scale mode of the viewer.
                    // Three modes exist currently:
                    // FIT_PAGE - The whole report will fit on the page (will zoom in or out), regardless of its width and height.
                    // FIT_PAGE_WIDTH - The report will be zoomed in or out so that the width of the screen and the width of the report match.
                    // SPECIFIC - Uses the scale to zoom in and out the report.
                    scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,

                    // Zoom in and out the report using the scale
                    // 1.0 is equal to 100%, i.e. the original size of the report
                    scale: 1.0,

                    ready: function () {
                        //this.refreshReport();
                    },
                });
        });
    </script>

9 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 13 Apr 2017, 10:38 AM
Hi Randy,

The code will create an HTML5 Viewer on the page.
Then you can use Javascript to update the viewer's reportSource.
Tha the place of the reportSource().report you need to use a string specifying a relative server path to a TRDX|TRDP file or the assembly qualified name of a report created in VS Report Designer (<namespace>.<report_class_name>, <assembly_name>).
For more details, please check How to: Set ReportSource for Report Viewers.


Note that you need a reference to the report's project in the Reporting REST Service's project (the one that holds the ReportsController inheriting ReportControllerBase).

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Randy
Top achievements
Rank 1
answered on 14 Apr 2017, 01:07 PM
Thanks Stef. You covered how to specify a different report. How would I pass parameter(s) to the report definition?
0
Stef
Telerik team
answered on 18 Apr 2017, 04:02 PM
Hi Randy,

You need to use the viewer's reportSource.

On creating teh viewer, you can set the reportSource().report and reportSource().parameters, which will determine which report will be displayed and what initial values will be used by its report parameters.

Then on updating the existing viewer, you can pass a new string information about the report you want to display, and/or new report parameters' values - How To: Pass Values to Report Parameters.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Randy
Top achievements
Rank 1
answered on 20 Apr 2017, 04:12 PM

Hi Stef - It seems I'm not able to get something right. In my .cshtml file I have this:

     //ReportSource - report description
                    reportSource: {
                        // The report can be set to a report file name (trdx report definition) 
                        // or CLR type name (report class definition).
                        report: "JeffreysOnline.Reporting.RentReceipt, JeffreysOnline.Reporting"
                    },
JeffreysOnline.Reporting is the name of the assembly

JeffreysOnline.Reporting.RentReceipt is the name space plus the report name. The report name is 'RentReceipt'. I also have a reference to the assembly in the project containing the HTML viewer. When I attempt to execute the report, I get this error:

Unable to get report parameters.
Report 'JeffreysOnline.Reporting.RentReceipt%2C%20JeffreysOnline.Reporting' cannot be resolved.

Can you tell me what I have wrong?

0
Stef
Telerik team
answered on 20 Apr 2017, 04:32 PM
Hi Randy,

The report's DLL must be referenced by the project containing the Reporting REST Service.
Open the report project's Properties in Visual Studio and check the assembly name. Also open the report's code-behind and copy the namespace and class name from there.
The assembly qualified name of a type is a case sensitive string.

If the report has entries in its ReportParameters collection, verify each report parameter has a default value in the designed report or/and it is visible. If there is a report parameter without set Value property and with Visible=false property, the report will fail being processed.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Randy
Top achievements
Rank 1
answered on 20 Apr 2017, 04:36 PM

Thanks for your help and patience Stef. I got past the above issue. Now I've encountered another. When the report starts to render, in the browser, I'm getting the error below. However, I do not get this error if I render it in design mode by clicking on the Preview tab. The report renders as I would expect in the Preview tab. I think I have my connection set correctly or it wouldn't render in the Preview tab.

An error has occurred while processing Report 'RentReceipt':
Unable to establish a connection to the database. Please, verify that your connection string is valid. In case you use a named connection string from the application
configuration file, make sure the name is correct and the connection string settings are present in the configuration file of your application.
------------- InnerException -------------
Format of the initialization string does not conform to specification starting at index 0

0
Stef
Telerik team
answered on 20 Apr 2017, 04:51 PM
Hi Randy,

The error means that the reporting engine cannot find the connection string(s) used by the report in the project's configuration file.

Please open the report in a report designer and check each SqlDataSource component in it and the value of the SqlDataSource.ConnectionString properties.

If you use named connection strings, in the Reporting REST Service's project configuration file you have to add entries under connectionStrings with these names. The reporting engine searches the connection strings by name in the configuration file.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Randy
Top achievements
Rank 1
answered on 21 Apr 2017, 11:37 AM
Thanks to your help, I have everything working now. One last question for now. I have a number of reports where the user always wants say 2 or 3 copies. Is there a setting in the HTML5ReportViewer definition where I can set the number of copies? If possible, I don't want to make my users always enter say 3 for a certain report. Also, is there a way a report can go directly to the printer without a print preview showing first?
0
Stef
Telerik team
answered on 21 Apr 2017, 06:04 PM
Hello Randy,

The client-side printing is based on export in PDF with Adobe Javascript that forces the PDF reader or browser's PDF plugin to open its Print dialog - Printing Reports. Since the printing happens at the client, the user confirmation and Print dialog cannot be omitted.

If you print from a printer machine connected to the server machine, then you can print through via ReportProcessor allowing you to pass custom PrinterSettings - ReportProcessor.PrintReport. Note that the PrinterSettings must be valid as there must not be a dialog when you run the operation in the background.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Randy
Top achievements
Rank 1
Answers by
Stef
Telerik team
Randy
Top achievements
Rank 1
Share this question
or