Passing an array of parameters from html viewer to Active Reports web service

Posted by: carolynlschroeder on 28 August 2018, 2:27 am EST

    • Post Options:
    • Link

    Posted 28 August 2018, 2:27 am EST

    I am trying to set up a Active Reports web service like this blog:

    https://www.grapecity.com/en/blogs/how-to-use-activereports-in-aspnet-core-20

    I need to pass an array of parameters from the client html web viewer to the Active Reports web service. How can this be done?

  • Posted 28 August 2018, 6:20 pm EST

    Hello,

    You can use the “reportParameters” option for the parameterized report to pass the parameter to the web service from the HTML5 Viewer.

    Please refer to the “reportParameter” option in the following link:

    http://help.grapecity.com/activereports/webhelp/AR12/webframe.html#HTML5WorkingwithViewerUsingJavascript.html.

    Also, please explain in detail if the above solution does not match with your requirements.

    Thanks,

  • Posted 29 August 2018, 1:06 am EST

    Thanks for your response. These parameters are determined at runtime. How would that work?

  • Posted 29 August 2018, 1:31 am EST

    To clarify, even the number of parameters is determined at runtime.

  • Posted 29 August 2018, 3:06 am EST

    I have been trying to use a multivalue parameter parameter1 in my report. I cannot seem to add it to my datasource. I went back to trying a single value parameter. I have tried:

    field = <%param:parameter1%> which gives an incorrect syntax error. I have tried both field = @parameter1 and field = parameter1 but for both get the error must declare parameter1 even though it is in the designer.

  • Posted 29 August 2018, 6:21 pm EST

    Hello Carolyn,

    You can create the Report id according to the runtime parameters as follow:

    
       <script type="text/javascript">
            $(function () {
    
                GrapeCity.ActiveReports.Viewer({
                    element: '#viewerContainer',
                    reportService: {
                        url: 'http://localhost:50058/WebService1.asmx'
                    },
                    report: { id: 'rpt_Bind.rpx?Country=\'USA\',City=\'Portland\'' },
                    uiType: 'desktop'
                });
            });
    
    

    After, create the custom report service to set the parameter in the report data source as follow:

    
      public class WebService1 :  GrapeCity.ActiveReports.Web.ReportService
        {
            [WebMethod]
            protected override object OnCreateReportHandler(string reportPath)
    
            {
                string reportname = reportPath.Substring(0,reportPath.IndexOf('?'));
                if (reportname == "rpt_Bind.rpx")
                {
                    // Separate the parameter from the string in form of Key and Value
                    string parameters = reportPath.Substring(reportPath.IndexOf('?') + 1);
                    string[] parameterList = parameters.Split(',');
                    Hashtable ht = new Hashtable();
                    foreach (string t in parameterList)
                    {
    
                        string[] parameter = t.Split('=');
                        ht.Add(parameter[0], parameter[1]);
                    }
    
                    //Constructs the SQl Query
                    string cmdText = "Select * From Customers Where ";
                    foreach (DictionaryEntry t in ht)
                    {
                        cmdText = cmdText + t.Key.ToString() + "=" + t.Value.ToString() + "AND ";
    
                    }
                    cmdText = cmdText.Substring(0, cmdText.Length - 4);
                    OleDbConnection connect = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\mohitg\Documents\GrapeCity Samples\ActiveReports 12\Data\NWIND.mdb; Persist Security Info = False");
                    //set up connection string
                    OleDbCommand command = new OleDbCommand(cmdText, connect);
                    //middle tier to run connect
                    OleDbDataAdapter da = new OleDbDataAdapter(command);
                    DataTable dset = new DataTable();
                    da.Fill(dset);
                    GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();
                    System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "/rpt_Bind.rpx");
                    sectionReport.LoadLayout(xtr);
                    xtr.Close();
                    sectionReport.DataSource = dset;
    
                    return sectionReport;
                }
    
                else
                    return base.OnCreateReportHandler(reportPath);
            }
    
        }
    
    
    

    hope it helps.

    Thanks,

  • Posted 29 August 2018, 10:36 pm EST

    Thanks, yes that works.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels