CustomReportResolver, where are the parameters?

4 posts, 0 answers
  1. Rick
    Rick avatar
    17 posts
    Member since:
    Sep 2011

    Posted 07 Mar Link to this post

    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;
                }
            }
    }

  2. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 10 Mar Link to this post

    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
  3. DevCraft banner
  4. Rick
    Rick avatar
    17 posts
    Member since:
    Sep 2011

    Posted 10 Mar in reply to Stef Link to this post

    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.

  5. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 12 Mar Link to this post

    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
Back to Top