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

Setting parameters at runtime (html viewer)

7 Answers 500 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Iron
Iron
Iron
Al asked on 10 Aug 2016, 01:27 PM

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

7 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 10 Aug 2016, 03:14 PM
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
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 11 Aug 2016, 09:13 AM

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).

0
Stef
Telerik team
answered on 12 Aug 2016, 11:07 AM
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
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 12 Aug 2016, 12:01 PM

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?

0
Stef
Telerik team
answered on 12 Aug 2016, 03:42 PM
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
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 15 Aug 2016, 08:10 AM

Thanks Stef,

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

0
Stef
Telerik team
answered on 15 Aug 2016, 01:23 PM
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
Tags
General Discussions
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Stef
Telerik team
Al
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or