Setting parameters at runtime (html viewer)

8 posts, 0 answers
  1. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 10 Aug Link to this post

    Hi,

    I use trdx files for my reports and switch the database connection at runtime using the connection string manager code here, that code is used in a custom resolver.

    Everything works fine but I have now added a parameter to my report that I would like to set the value of in c# at rutime. Looking through the connection manager code listed above I find that 'originalReportSource.Parameters' as below is empty - surely this should contain the parameter that is defined in my report or am I missing something?

    ReportSource CreateInstanceReportSource(IReportDocument report, ReportSource originalReportSource)
    {
        var instanceReportSource = new InstanceReportSource { ReportDocument = report };
        instanceReportSource.Parameters.AddRange(originalReportSource.Parameters);
        return instanceReportSource;
    }

  2. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 10 Aug Link to this post

    Hello Al,

    The report source object is not aware of the report's settings. The ReportSource.Parameters collection is mapped by key(name) to the report's ReportParameters collection, where you need to add elements in the ReportSource.Parameters collection - Report Sources.

    Note that in a custom resolver for the Reporting REST service, you will receive only the string description of the report (the viewer's reportSource.Report string). The client parameters (viewer's reportSource.parameters collection) will be applied on the already resolved report. If you want to pass information from the client, add it in the string describing the report. Then in the custom resolver update the report instance's ReportParameters collection directly. In case the client submits another value for the same report parameter, the client's value will override the one set in the custom resolver.

    In addition, please update the ReportsControllerBase implementation based on How To: Implement the ReportsController in an application.

    Regards,
    Stef
    Telerik by Progress
    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. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 11 Aug in reply to Stef Link to this post

    Thanks Stef but I am struggling to follow this to be honest. I use the html viewer with a reports controller and a custom resolver to load pre-defined trdx files (designed with the report designer) - this is all working fine.

    1. If 'originalReportSource.Parameters' is always empty in 'CreateInstanceReportSourec' above then why is it used in that routine?

    2. I use a custom resolver which sets the connection string dynamically using your 'ReportConnectionStringManager' class, could you pls post some code to show how I can set an existing report parameter (I will know the name).

  5. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 12 Aug Link to this post

    Hi Al,

    The idea is that when you are creating the ReportSource you are passing values to report parameters through the ReportSource.Parameters collection e.g. when you configure a NavigateToReportAction target or a SubReport item's report. Thus on creating a new ReportSource, the Parameters collection of the original ReportSource should be transferred.

    If you prefer, you can modify the method to read the report's ReportParameters collection and to add an entry per report parameter in the final ReportSource object.
    For example:
    ReportSource CreateInstanceReportSource(IReportDocument report, ReportSource originalReportSource)
        {
            var instanceReportSource = new InstanceReportSource { ReportDocument = report };
           // instanceReportSource.Parameters.AddRange(originalReportSource.Parameters);
             foreach(var p in report.ReportParameters)
             {
                 instanceReportSource.Parameters.Add(p.Name,"some value");
             }
            return instanceReportSource;
        }


    Regards,
    Stef
    Telerik by Progress
    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
  6. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 12 Aug in reply to Stef Link to this post

    Thanks Stef,

    If I use your code above then my parameters does not get set when the report runs (I can see the parameter box is empty). While waiting for your reply I tried some experiments and this did seem to work (pseudo-code):

    var ReportSource rs = CreateInstanceReportSource(reportInstance, uriReportSource);
     
     foreach (var reportParm in (rs as InstanceReportSource).ReportDocument.ReportParameters)
     {                      
         reportParm.Value = "some value";                                             
    }

    ie. setting the parameter value directly on the ReportDocument works fine but setting on the report instance as you suggested does not work?

  7. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 12 Aug Link to this post

    Hi Al,

    The code will update directly the report's ReportParameters collection, where you can also provide default values on designing the report.

    In your case, most probably the report does not have nested SubReport items and/or NavigatetoReportAction settings. Thus you are updating only the ReportSource that is returned by the custom resolver's Resolve method. This report source's Parameters collection is ignored, as in a consecutive request by the viewer, the client's reportSource.parameters collection is applied on the returned report source object. In such case you need to modify directly the report instance's ReportParameters collection.

    Regards,
    Stef
    Telerik by Progress
    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
  8. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 15 Aug in reply to Stef Link to this post

    Thanks Stef,

    This is very confusing for me but anyway are you saying what I am doing is fine?

  9. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 15 Aug Link to this post

    Hi Al,

    The code should work. It is setting values directly in the report instance's ReportParameters collection, per report parameter.

    Regards,
    Stef
    Telerik by Progress
    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
DevCraft banner