Programmaticaly passing params to ReportBook childs Reports

2 posts, 0 answers
  1. Nauman
    Nauman avatar
    2 posts
    Member since:
    Apr 2019

    Posted 01 Oct Link to this post

    I am working .net core rest api backend and angular front end.

    I am trying to make a ReportBook adding reports to programmatically.

    Front End TypeScript

    reportReady() {
      const reportSource = this.viewer.getReportSource();
      reportSource.report =  1 + '_' + this.id;
      const params = reportSource.parameters;
      params.summaryId = this.id;
      params.baseurl = Config.getServerUrl();
      params.OriginalOrDuplicateParam = '';
      reportSource.parameters = params;
      this.viewer.setReportSource(reportSource);
    }

     

    Backend i have reports controller with Custom Report Resolver 

    private InstanceReportSource InvoiceSummaryReportBook(string reportId)
                {
                    try
                    {
                        InstanceReportSource result = new InstanceReportSource();
                        using (var db = new FilteredHahnDbContext())
                        {
                            var summaryId = reportId.Split("_").LastOrDefault();
     
     
                            var summaryIdGuid = Guid.Parse(summaryId);
                            var summaryDetails = db.InvoiceSummaryDetails.Include(x => x.Invoice)
                                .Where(x => x.InvoiceSummaryMasterId == summaryIdGuid).ToList();
     
                            // Creating a new report book
                            var reportBook = new ReportBook();
                            var typeReportSource = new Telerik.Reporting.TypeReportSource();
                            typeReportSource.TypeName = typeof(ReportBook).AssemblyQualifiedName;
     
                            //Add first report
                            var glossaryReportSource = new UriReportSource();
                            glossaryReportSource.Uri = this.MapPath("InvoiceSummaryReport.trdp");
                            reportBook.ReportSources.Add(glossaryReportSource);
     
     
                            var params1 = new ParameterCollection();
     
                            var index = 0;
                            foreach (var summaryDetail in summaryDetails)
                            {
                                if (summaryDetail.Invoice.InvoiceTypeId == EInvoiceType.Individual)
                                {
                                    var glossaryReportSource2 = new UriReportSource();
                                    glossaryReportSource2.Parameters.Add("invoiceId", summaryDetail.InvoiceId.ToString());
                                    result.Parameters.Add($"reports({index}).invoiceId", summaryDetail.InvoiceId.ToString());
                                    typeReportSource.Parameters.Add($"reports({index}).invoiceId", summaryDetail.InvoiceId.ToString());
     
                                    glossaryReportSource2.Uri = this.MapPath("IndividualInvoice.trdp");
                                    reportBook.ReportSources.Add(glossaryReportSource2);
                                }
                                else
                                {
                                    var glossaryReportSource2 = new UriReportSource();
                                    glossaryReportSource2.Parameters.Add("invoiceId", summaryDetail.InvoiceId.ToString());
                                    result.Parameters.Add($"reports({index}).invoiceId", summaryDetail.InvoiceId.ToString());
                                    typeReportSource.Parameters.Add($"reports({index}).invoiceId", summaryDetail.InvoiceId.ToString());
     
                                    glossaryReportSource2.Uri = this.MapPath("OrderInvoice.trdp");
     
                                    reportBook.ReportSources.Add(glossaryReportSource2);
                                }
     
                                index++;
                            }
     
                            reportBook.TocReportSource = typeReportSource;
                            //Return the new instance
                            result.ReportDocument = reportBook;
     
                            return result;
     
                        }
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }

     

    Above Method used in

    public ReportSource Resolve(string reportId)
    {
        InstanceReportSource result = null;
     
        var rprtId = reportId.Split("_").FirstOrDefault();
     
        switch (rprtId)
        {
            // 1 Invoice Summary ReportBook
            case "1":
                result = InvoiceSummaryReportBook(reportId);
                break;
        }
     
        return result;
    }

     

    For each report "invoiceId" is different. As you can see in code i am trying three different methods to pass parameters but none are taking effect.

  2. Nauman
    Nauman avatar
    2 posts
    Member since:
    Apr 2019

    Posted 01 Oct Link to this post

    Problem Resolved

    I have sent params from front end in this fromat {reports(1).invoiceId": 103}
Back to Top