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

CustomReportResolver, where are the parameters?

3 Answers 688 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 2
Rick asked on 07 Mar 2016, 10:27 PM

I've created a customreportresolver in my project (mvc) so that I can make changes to the connection string (and other stuff) on the fly. I'm passing a dictionary<string,object> from my mvc view with the settings for all the report's parameters.

How does that dictionary get to my customreportresolver? I'm not seeing the parameters in my report being updated from the dictionary. 

@{
    var parameters = new Dictionary<string, object>();
    parameters.Add("s1", Model.ReportGeneratorOutput.s1);
    parameters.Add("s2", Model.ReportGeneratorOutput.s2);
    parameters.Add("g1", Model.ReportGeneratorOutput.g1);
    parameters.Add("sourceflag", Model.ReportGeneratorOutput.SourceFlag);
    parameters.Add("sid", Model.ReportGeneratorOutput.Sid);
    parameters.Add("hdr1", Model.ReportGeneratorOutput.hdr1);
    parameters.Add("hdr2", Model.ReportGeneratorOutput.hdr2);
    parameters.Add("session", Model.Session);
}
<div id="reportOutput">
    @(Html.TelerikReporting().ReportViewer()
        .Id("reportViewer")
        .ServiceUrl("/api/reports")
        .ReportSource("Report.trdx", parameters)
        .ViewMode(ViewMode.Interactive)
        .PersistSession(false)
        .ScaleMode(ScaleMode.FitPage)
    )
</div>

public class CustomReportResolver : Telerik.Reporting.Services.Engine.IReportResolver
    {
        public ReportSource Resolve(string source)
        {
            var settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
 
            using (var xmlreader = XmlReader.Create(Path.Combine(HttpContext.Current.Server.MapPath("~/Reports"), source), settings))
            {
                var serializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
                var report = (Report)serializer.Deserialize(xmlreader);
 
                //need to set the correct connection string here
                //the parameter: session has the year
 
                //var efconnection = ConfigurationManager.ConnectionStrings[$"Connection{report.ReportParameters["session"].Value}"].ConnectionString;
                //var connection = new EntityConnectionStringBuilder(efconnection).ProviderConnectionString;
 
                //SetConnectionString(report, connection);
                 
                var instancereport = new InstanceReportSource { ReportDocument = report };
                return instancereport;
            }
        }
}

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 10 Mar 2016, 04:41 PM
Hi Rick,

The client's parameters values are not available in the custom resolver's Resolve method. The Resolve method gets the client(viewer)'s reportSource.report string property. On a consecutive call the viewer sends the client's parameters values which are applied on the resolver ReportSource.

If you need the values in the custom resolver's Resolve method, you can use the viewer's reportSource.report and pass a long string containing the concatenated values.


In order to provide you more accurate suggestions, please elaborate on the usage of the values for resolving the report on the server.

Regards,
Stef
Telerik
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
Rick
Top achievements
Rank 2
answered on 10 Mar 2016, 10:22 PM

Thanks for the answer. I think I've seen someone else convert the parameters to a json string and pass that to the custom Resolve method. Guess that will have to do for now.

One of the things I need from the parameters is what year is being reported on so that I can change the sql connection string dynamically. I also want to remove items from the report xml definition if they aren't requested to be on the report. This is all passed from various forms the user fills out while using our product. I could use report parameters but there are more than 40 items on the report that might need to be hidden and it will be easier to do that with some code dynamically.

0
Stef
Telerik team
answered on 12 Mar 2016, 03:10 PM
Hi Rick,

Thank you for the additional information.

Items and sections visibility can be controlled via bindings and conditional formatting based on report parameters. Report parameters can be visible and displayed in the viewer's parameters area; or hidden and updated via custom UI that refreshes the viewer's reportSource.parameters collection - How To: Pass Values to Report Parameters.

About updating the SQL query, please check if using a parameterized data-retrieval method helps you to achieve the desired functionality without modifying the report at run-time. For example, check SqlDataSource Wizard(step 4) and Using Parameters with the SqlDataSource component.

Regards,
Stef
Telerik
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
Rick
Top achievements
Rank 2
Answers by
Stef
Telerik team
Rick
Top achievements
Rank 2
Share this question
or