Search results

Report Parameters

Provides property options to pass or set report parameters default values at run time using the parameters property. You can set the report parameters while creating the Report Viewer control in a script or in the Web API Controller.

In this tutorial, the Sales Order Detail.rdl report is used, and it can be downloaded from here.

Set parameter at client side

The parameters property takes the JSON array value input with parameter details.

  • Set the default value data to the values property and name of the report parameter to the name property.

    The parameter name is case sensitive, and it should be same as available in the report definition.

The following code example illustrates how to set a report parameter in the script.

<ej-reportviewer id="reportViewer_Control" [reportServiceUrl] = "serviceUrl" [processingMode] = "Remote" [reportPath] = "reportPath" [parameters] = "parameters">
</ej-reportviewer>
import { Component } from '@angular/core';

@Component({
    selector: 'ej-app',
    templateUrl: 'src/reportviewer/reportviewer.component.html',
    styleUrls: ['src/reportviewer/reportviewer.component.css']
})

export class ReportViewerComponent {
    public serviceUrl: string;
    public reportPath: string;
    public serverUrl: string;
    public parameters: any;

    constructor() {

        this.serviceUrl = 'https://reports.syncfusion.com/demos/services/api/ReportViewer';
        this.reportPath = 'Sales Order Detail.rdl';
        this.parameters = [{
            name: 'SalesOrderNumber',
            labels: ['SO50751'],
            values: [SO50751],
            nullable: false
            }];
    }
}
  • Build and run the application.

Set parameters in Web API Controller

To set parameter default value in the Web API Controller, use the following code in the OnReportLoaded method.

public void OnReportLoaded(ReportViewerOptions reportOption)
{
    List<Syncfusion.Reporting.Web.ReportParameter> userParameters = new List<Syncfusion.Reporting.Web.ReportParameter>();
    userParameters.Add(new Syncfusion.Reporting.Web.ReportParameter()
    {
        Name = "SalesOrderNumber",
        Values = new List<string>() { "SO50756" }
    });
    reportOption.ReportModel.Parameters = userParameters;
}

Get report parameter

The ReportHelper class provides methods that help you to get the report parameters used in the report. The following helper methods are used to get parameter with or without values.

Methods Description
GetParameters Returns the parameters used in the current report without the processed values.
GetParametersWithValues Returns the report parameters with processed data values that are used in the current report.

You can use the following code sample to get parameter names and set parameter default values.

    public class ReportsApiController : ApiController, IReportController
    {
        Dictionary<string, object> jsonArray = null;
        public object PostReportAction(Dictionary<string, object> jsonResult)
        {
            jsonArray = jsonResult;
            return ReportHelper.ProcessReport(jsonResult, this);
        }

        ....
        public void OnReportLoaded(ReportViewerOptions reportOption)
        {
            var reportParameters = ReportHelper.GetParameters(jsonArray, this);
            List<Syncfusion.Reporting.Web.ReportParameter> setParameters = new List<Syncfusion.Reporting.Web.ReportParameter>();

            if (reportParameters != null)
            {
                foreach (var rptParameter in reportParameters)
                {
                    setParameters.Add(new Syncfusion.Reporting.Web.ReportParameter()
                    {
                        Name = rptParameter.Name,
                        Values = new List<string>() { "SO50756" }
                    });
                }

                reportOption.ReportModel.Parameters = setParameters;
            }
        }
    }