Search results
Suggest a FeaturePDF

How to pass multiple values using the custom data

Pass the multiple data values as JSON in ajaxBeforeLoad event using the ‘data’ property, which needs to be serialized in the server side API using known class type and JsonConvert.DeserializeObject.

  1. Map the ajaxBeforeLoad event with onAjaxRequest function in the client side to pass custom data to the server.

    <bold-reportviewer id="reportViewer_Control"
     [reportServiceUrl] = "serviceUrl"
     [processingMode] = "Remote"
     [reportServerUrl] = "serverUrl"
     [reportPath] = "reportPath"
     (ajaxBeforeLoad) = "onAjaxRequest($event)">
    </bold-reportviewer>
    function onAjaxRequest(args) {
    //Passing custom data to server
    }
  2. You need to pass the multiple custom data values as JSON and use the data property to send the JSON string to the server in the Ajax request.

    function onAjaxRequest(args) {
    //Passing custom data to server
    var jsonData = {
                     customerID: "CI0021",
                     productID: "PO0022"
                   };
    args.data = jsonData;
    }
  3. The custom data values are stored in the customData header key, and you can store them in the local property. The following code sample demonstrates deserialization of the JSON string and change the data source connection strings based on Customer ID and Product ID in the OnInitReportOptions method.

    public SampleData customDatas = new SampleData();
    
    public class SampleData
    {
        public string customerID { get; set; }
        public string productID { get; set; }
    }
    
    [HttpPost]
    public object PostReportAction([FromBody]Dictionary<string, object> jsonResult)
    {
        if (jsonResult.ContainsKey("customData"))
        {
            //Get client side JSON custom data, desirialize it and store in local variable.
            customDatas = JsonConvert.DeserializeObject<SampleData>(jsonResult["customData"].ToString());
        }
        return ReportHelper.ProcessReport(jsonResult, this, this._cache);
    }
    
    public void OnInitReportOptions(ReportViewerOptions reportOption)
    {
        if (customDatas != null)
        {
            if (customDatas.customerID == "CI0021" && customDatas.productID == "PO0022") {
            //If you are changing the connection string based on customer id then could you please change the connection string as below.
            //reportOption.ReportModel.DataSourceCredentials.Add(new BoldReports.Web.DataSourceCredentials("<Datasource name>", "<connection string>"));
            reportOption.ReportModel.DataSourceCredentials.Add(new BoldReports.Web.DataSourceCredentials("<database>", "Data Source=<instancename>;Initial Catalog=<database>;"));
            }
        }
    }
Having trouble getting help?
Contact Support
Having trouble getting help?
Contact Support