Accessing Angular tr-viewer parameters on backend with report C# file

2 Answers 122 Views
Report Viewer - Angular Report Viewer - MVC
Joel
Top achievements
Rank 1
Iron
Joel asked on 23 Jun 2021, 02:56 PM

I am having difficulty accessing report params on the backend in order to properly generate a report. I am able to generate a blank report. But the backend is not receiving the parameters from the angular tr-viewer

on the front I have a tr-viewer with params { MemberID: 59, Date: '3/31/2021', }

    #totalReport1
    [containerStyle]="viewerContainerStyle"
    [serviceUrl]="'http://localhost:1088/api/reportapi/'"
    [reportSource]="{
        report: 'ReportAssetAllocation',
        parameters: { MemberID: 59, Date: '3/31/2021' }
    }"
    [viewMode]="'INTERACTIVE'"
    [scaleMode]="'SPECIFIC'"
    [scale]="1.0"
    [ready]="ready"
    [viewerToolTipOpening]="viewerToolTipOpening"
    [enableAccessibility]="true"
>
</tr-viewer>

The report is generated in the C# constructor below

Please note that the way data is being fetched below was with a previous version of this application which used angularjs and took in the parameters through http headers.

    public partial class ReportAssetAllocation : Telerik.Reporting.Report
    {
        public int MemberID { get; set; }
        public string Date { get; set; }

        public ReportAssetAllocation()
        {
            try
            {
                if (HttpContext.Current.Request.Headers.GetValues("memberID") != null)
                {
                    MemberID = Convert.ToInt32(HttpContext.Current.Request.Headers.GetValues("memberID")[0]);                     
                    Date = Convert.ToString(HttpContext.Current.Request.Headers.GetValues("Date")[0]);
                }
            }
            catch { }

            InitializeComponent();
        }

I want to modify this constructor to accept the params from the Angular tr-viewer but I have not had any success in doing this after trying multiple methods from other posts and documentation.

What is best way to access these reportSource parameters { MemberID: 59, Date: '3/31/2021', } in my C# file?

 

 

For reference, here is the report api controller just in case:

  public class ReportApiController : ReportsControllerBase
    {
        static readonly ReportServiceConfiguration preservedConfiguration;

        static ReportApiController()
        {
            {
                var resolver = new UriReportSourceResolver(HttpContext.Current.Server.MapPath("~/Reports"))
                    .AddFallbackResolver(new TypeReportSourceResolver()
                        .AddFallbackResolver(new TypeReportSourceResolver()));

                preservedConfiguration = new ReportServiceConfiguration
                {
                    HostAppId = "REPORTS",
                    ReportSourceResolver = resolver,
                    Storage = new Telerik.Reporting.Cache.File.FileStorage(),
                };
                var assemblyName = typeof(ReportCatalog).AssemblyQualifiedName;
                var namespaceOfClass = typeof(ReportAssetAllocation).Namespace;
            }
        }

        public ReportApiController()
        {
            this.ReportServiceConfiguration = preservedConfiguration;
        }
    }

 

Thank you

2 Answers, 1 is accepted

Sort by
1
Accepted
Dimitar
Telerik team
answered on 28 Jun 2021, 08:40 AM

Hi Joel,

Thank you for the provided information.

Is there any specific reason for wanting to modify the constructor of your custom report? 

I think it should be much easier to pass the values of the Angular report viewer's report parameters to the report, through the Report.ReportParameters Property as in the example in the Using Report Parameters programmatically.

As for how to obtain the values that are passed from the report viewer, you may implement a custom ReportSourceResolver - How to Implement a Custom Report Source Resolver. The IReportSourceResolver.Resolve Method's third parameter - currentParameterValues is a dictionary and represents the parameter values coming from the report viewer client.

Please let me know if you have any other questions or need further help. Thank you for using Telerik Reporting!

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Joel
Top achievements
Rank 1
Iron
commented on 28 Jun 2021, 12:19 PM

Thank you. Solution was to get params using sender object, not the constructor.

private void reportReport_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
MemberID = Convert.ToInt32(report.Parameters["MemberID"].Value);
}
0
Joel
Top achievements
Rank 1
Iron
answered on 28 Jun 2021, 12:20 PM | edited on 28 Jun 2021, 12:22 PM

In case anyone runs into a similar problem and finds this post, here is the solution:

 


private void reportReport_NeedDataSource(object sender, EventArgs e)
{
Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
MemberID = Convert.ToInt32(report.Parameters["MemberID"].Value);
Date = report.Parameters["Date"].Value;
}

Tags
Report Viewer - Angular Report Viewer - MVC
Asked by
Joel
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Joel
Top achievements
Rank 1
Iron
Share this question
or