Starting in 2019, the Reporting control is no longer included in Essential Studio®. If you're experiencing issues with the Syncfusion� Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion� and appreciate your understanding.

Setting Report parameters

Hello. I have been working with your solutions for two weeks and I'm using your JS implementation of Report Viewer. My main goal is to set programmatically parameters for reports. I've tried your solutions from other threads (e.g. ids: 126152, 124300)  and while loading report (without parameters set) I cannot get any response via your's prototype function: 
However if I'm not using your's prototype function (also without parameters set) I get response and report shows up (I assume that Report Server works properly). 
Setting parameters in inputs rendered by report viewer also gives us proper report. The only solution for now is to set values of inputs programmatically and firing 'View report' button. I find that solution dirty and not professional. There must be other way to solve this issue. Please help. 

15 Replies

YD Yuvaraj Devarajan Syncfusion Team February 8, 2018 06:53 AM UTC

Hi Oskar, 

Thanks for contacting Syncfusion support. 

The mentioned prototype method is used to filter the datasource value based on parameter only for RDLC report. Our ReportViewer has support to set/pass the default value of the parameter in the control render viewer as shown in below code example, 

JS: 
    <script type="text/javascript"> 
        $(function () { 
            $("#container").ejReportViewer( 
                { 
                    reportServiceUrl: '/api/ReportApi',                 
                    processingMode: ej.ReportViewer.ProcessingMode.Remote, 
                    reportPath: '~/App_Data/Dependent.rdl', 
                    parameters: [{ 
                        name: 'ReportParameter1', 
                        labels: ['Bikes','Components'], 
                        values: [1,2],                        
                    }], 
                }); 
        }); 
        
    </script> 

We have prepared a sample and it can be downloaded from below location, 

Please refer to the below UG documentation link for more detail, 

Regards, 
Yuvaraj D. 



OM Oskar Morawiec February 8, 2018 08:41 AM UTC

Thanks for your respons. 
Your code works fine, I can pass parameters and report shows up. But, is there any option to change parameters dynamicly? Not all Reports have parameters which needs to be set, so I have to check, when pass parameters or not. Or, is there option to check which reports uses these parameters without download report and render it?


YD Yuvaraj Devarajan Syncfusion Team February 9, 2018 01:14 PM UTC

Hi Oskar, 

We have option to pass the parameter value dynamically from viewer to WebAPI to set the value of parameter using only doAjaxPost method in control render viewer page as shown in following code example, 

View: 
<script> 
    var _params = null; 
    function onChange(args) { 
        var proxy = $('#reportsample').data('ejReportViewer'); 
        reportParam = []; 
        reportParam.push({ name: 'ReportParameter1', labels: [args.text], values: [args.value], nullable: false }); 
        proxy.model.parameters = reportParam; 
        parameters = reportParam; 
        proxy._refreshReport(); 
    } 
 
    ej.ReportViewer.prototype.doAjaxPost = function (type, url, jsondata, onSuccess) { 
        var proxy = $('#reportsample').data('ejReportViewer'); 
        var inVokemethod = onSuccess; 
 
        $.ajax({ 
            type: type, 
            url: url, 
            crossDomain: true, 
            contentType: 'application/json; charset=utf-8', 
            dataType: 'json', 
            data: jsondata, 
            beforeSend: function (req) { 
                if (inVokemethod == "_getDataSourceCredential") { 
                    var _json = jQuery.parseJSON(this.data); 
                    if (_params != null) { 
                        _json["params"] = _params; 
                    } 
                    this.data = JSON.stringify(_json); 
                } 
 
                if (inVokemethod == "_getPageModel" || inVokemethod == "_getPreviewModel") { 
                    if (!proxy._isToolbarClick) { 
                        proxy._showloadingIndicator(true); 
                        proxy._updateDatasource = true; 
                    } else { 
                        proxy._showNavigationIndicator(true); 
                    } 
                } 
                req.setRequestHeader('ejAuthenticationToken', proxy._authenticationToken); 
            }, 
            success: function (data) { 
                if (data && typeof (data.Data) != "undefined") { 
                    data = data.Data; 
                } 
                if (typeof (data) == "string") { 
                    if (data.indexOf("Sf_Exception") != -1) { 
                        proxy._renderExcpetion(inVokemethod + ":" + data); 
                        return; 
                    } 
                } 
                proxy[inVokemethod](data); 
            }, 
        }); 
    } 
</script> 
 

webAPI: 
public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            var parameters = new List<Syncfusion.Reports.EJ.ReportParameter>(); 
            if (System.Web.HttpContext.Current.Items.Contains("parakey")) 
            { 
                reportOption.ReportModel.Parameters = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<Syncfusion.Reports.EJ.ReportParameter>>(System.Web.HttpContext.Current.Items["parakey"].ToString()); 
                System.Web.HttpContext.Current.Items.Remove("parakey"); 
            }                               
        } 

We have prepared the sample based on this and it can be downloaded from, 

If we misunderstood your scenario, then please share the additional information with your scenario to provide the solution for this. 

Regards, 
Yuvaraj D. 



OM Oskar Morawiec February 9, 2018 01:34 PM UTC

Thanks for your reply. 
I only have access to client side, so I cannot modify WebAPI. Server is based on your implementation of WebAPI (https://help.syncfusion.com/report-platform/report-server/api/v2.0/). 
Is there any way to solve my problem without modifying WebAPI?


YD Yuvaraj Devarajan Syncfusion Team February 12, 2018 03:06 PM UTC

Hi Oskar, 

We can achieve your requirement by overriding the View report click event and pass the dynamic value for the report as shown in below code example, 

function OnParamChange() { 
            var proxy = $('#container').data('ejReportViewer'); 
            proxy._showloadingIndicator(true); 
            proxy._hidePageView(); 
            var reportParams = []; 
            reportParams.push({ name: 'SalesOrderNumber', labels: ['SO50751'], values: ['SO50751'], nullable: false }); 
            if (reportParams) { 
                proxy._viewReportEnableDisable(true); 
                proxy._refresh = true; 
                $('#' + proxy._id + '_viewBlockContainer .e-reportviewer-viewerblockcontent table:first').attr('data-isviewclick', 'true'); 
                proxy._onViewReportClick(reportParams); 
                proxy.doAjaxPost("POST", proxy._actionUrl, JSON.stringify({ 'reportAction': proxy._reportAction.setParameters, 'parameters': reportParams }), "_setParameters"); 
            } 
            else { 
                proxy._showloadingIndicator(false); 
            } 
            proxy._refreshReport(); 
        } 
   
We have prepared a sample and it can be downloaded from below location, 

Also, we can find the Report name which consists of the parameter when using the renderingComplete event at your end as shown in below code example, 
 
$("#container").ejReportViewer( 
                        { 
                            reportServiceUrl: "https://reportserver.syncfusion.com/ReportService/api/Viewer", 
                            serviceAuthorizationToken: token["token_type"] + " " + token["access_token"], 
                            reportPath: '/Sample Reports/Sales Order Detail', 
                            renderingComplete: onRenringComplete 
 
                        }); 

Please refer to the below UG documentation link for more detail, 

Regards, 
Yuvaraj D. 



OM Oskar Morawiec February 13, 2018 10:50 AM UTC

Thank you for response. Your solution works fine.
But I have another question. Can I hide parameters from toolbar? But only these which are passed programmatically. E.g. I want to hide this parameter, but secound one should stay as it is: 


YD Yuvaraj Devarajan Syncfusion Team February 14, 2018 03:17 PM UTC

Hi Oskar, 
   
We can hide the particular parameter in ReportViewer, dynamically in OnInitReportOptions method by editing the DOM file as shown in the code example below.    

WebAPI:  
public void OnInitReportOptions(ReportViewerOptions reportOption)  
        {  
            Syncfusion.RDL.DOM.ReportDefinition reportDefinition =this.DeSerializeReport(reportOption.ReportModel.ReportPath);  
            foreach (var param in reportDefinition.ReportParameters)  
            {  
                param.Hidden = true;  
            }  
            reportOption.ReportModel.Stream = GetStream(reportDefinition);  
            reportOption.ReportModel.ReportPath = string.Empty;             
        }  
 
We have prepared the sample based on this and it can be downloaded from below location,  

Please refer to the below KB documentation link for more detail, 

Regards, 
Yuvaraj D. 



OM Oskar Morawiec February 21, 2018 04:42 PM UTC

Hello. I get into another problem. Let's say that I have four parameters in my report. Two of them I need to pass programmatically and other two write by hand. I already use your solution to pass parameters programmatically but it doesn't work with passing some parameters by hand and some programmatically. How can I achieve this without changing WebAPI (only in JS)? E.g. this signed two parameters need to be passed programmatically and another two manualy: 


YD Yuvaraj Devarajan Syncfusion Team February 22, 2018 09:54 AM UTC

Hi Oskar, 

We checked the mentioned problem by passing the default parameter value and its working properly at our end. We suspect the mentioned problem might be occurred when you have specified the parameter name incorrectly when setting the default value for the particular parameter. So we request to ensure the parameter name specified properly in your application to avoid the mentioned problem at your end as shown in below screenshot, 

   

For your reference, we have prepared a sample and it can be downloaded from below location, 

Regards, 
Yuvaraj D. 



OM Oskar Morawiec replied to Yuvaraj Devarajan February 22, 2018 01:19 PM UTC

Hi Oskar, 

We checked the mentioned problem by passing the default parameter value and its working properly at our end. We suspect the mentioned problem might be occurred when you have specified the parameter name incorrectly when setting the default value for the particular parameter. So we request to ensure the parameter name specified properly in your application to avoid the mentioned problem at your end as shown in below screenshot, 

   

For your reference, we have prepared a sample and it can be downloaded from below location, 

Regards, 
Yuvaraj D. 


Hello. Thanks for your reply. This way works for me, but as i mentioned earlier first I need to know what parameters are for report. So I use your code:

function OnParamChange() { 
            var proxy = $('#container').data('ejReportViewer'); 
            proxy._showloadingIndicator(true); 
            proxy._hidePageView(); 
            var reportParams = []; 
            reportParams.push({ name: 'SalesOrderNumber', labels: ['SO50751'], values: ['SO50751'], nullable: false }); 
            if (reportParams) { 
                proxy._viewReportEnableDisable(true); 
                proxy._refresh = true; 
                $('#' + proxy._id + '_viewBlockContainer .e-reportviewer-viewerblockcontent table:first').attr('data-isviewclick','true'); 
                proxy._onViewReportClick(reportParams); 
                proxy.doAjaxPost("POST", proxy._actionUrl, JSON.stringify({ 'reportAction': proxy._reportAction.setParameters,'parameters': reportParams }), "_setParameters"); 
            } 
            else { 
                proxy._showloadingIndicator(false); 
            } 
            proxy._refreshReport(); 
        } 

to pass parameters programmatically. But in parallel with this solution I need to pass some parameters manually. Is there any way to achieve this?


MS Mahendran Shanmugam Syncfusion Team February 23, 2018 01:10 PM UTC

Hi Oskar, 
 
But in parallel with this solution I need to pass some parameters manually. Is there any way to achieve this? 
Can you please confirm whether you need to input the parameter values in user interface or need to add new parameter to RDL report at code. If it’s not your requirement then provide additional details on this, it would be helpful for us to provide the solution earlier. 
 
Regards, 
Mahendran S.  



OM Oskar Morawiec February 23, 2018 04:24 PM UTC

I will try describe user case. 
After choose report, some of them have parameters and some don't. E.g. we can see parameters to insert like this: 
Now there are to parameters which need to be fill up programmatically (in this case "ServerName" and "Database"), and other two need to be fill up by user (manualy). After filling up parameters user clicks "View Report" (at this moment ServerName and Database should be filled up programmatically), and expects proper report.
And my problem is with filling up this two parameters programmatically, and leaving other two to fill up manualy. Is there any way to manage this?  


VS Vinoth Srinivasan Syncfusion Team February 26, 2018 12:52 PM UTC

Hi Oskar, 

We have prepared a sample to set the values for the parameter in code behind  and the sample can be downloaded from the below location. 


Please find the below code snippet we have used to set the parameter from code behind. 

public void OnInitReportOptions(ReportViewerOptions reportOption) 
{ 
  List<ReportParameter> parameters = new List<ReportParameter>(); 
  parameters.Add(new ReportParameter() { Name = "ServerName", Values = new List<string>() { "Localhost" } }); 
  parameters.Add(new ReportParameter() { Name = "Database", Values = new List<string>() { "AdventureWorks" } }); 
  reportOption.ReportModel.Parameters = parameters; 
} 
 

Regards, 
Vinoth S. 



OM Oskar Morawiec February 26, 2018 02:56 PM UTC

Please can you read whole thread before response me? I'm using JS implementation of report viewer, and I cannot change anything on server side.


YD Yuvaraj Devarajan Syncfusion Team February 27, 2018 12:54 PM UTC

Hi Oskar, 

Please ignore our previous update,  

We can pass the default parameter value for the “ServerName”, “Database” parameter in client side and also you can set the “startDate”, “EndDate” parameter manually as shown in below code example,  

    <script type="text/javascript"> 
 
    $(function () { 
        $("#container").ejReportViewer( 
                    { 
                        reportServiceUrl: "/api/ReportApi", 
                        reportPath: '~/App_Data/GroupingAgg.rdl', 
                        processingMode: ej.ReportViewer.ProcessingMode.Remote, 
                        parameters: [{ 
                            name: 'ServerName', 
                            labels: ['Localhost'], 
                            values: ['Localhost'], 
                            nullable: false 
                        }, 
                        { 
                            name: 'Database', 
                            labels: ['AdventureWorks'], 
                            values: ['AdventureWorks'], 
                            nullable: false 
                        }] 
                    }); 
    }); 
 
    </script> 

For your reference, we have prepared a sample and it can be downloaded from below location, 

Please refer to the below UG documentation link for more detail, 

Regards, 
Yuvaraj D.

Loader.
Up arrow icon