How can I call a new report in the viewer?

3 posts, 0 answers
  1. Frank
    Frank avatar
    9 posts
    Member since:
    Feb 2019

    Posted 20 Feb Link to this post


    I have created an Angular project in which a report is displayed in the Report Viewer, which is loaded by the Report Server.
    As described in your example.

    I use the option "[reportSource]" to pass the following object:
      "{Report: categoryName / reportName}".

    Now I want to change this object to another report and show this.
    Unfortunately it did not work that easy.

    So I researched the documentation and found out that methods can be run on the viewer.

    refreshReport() and setReportSource() sounded good and I tried them as they did in your example.

    Unfortunately, that did not work either.
    In the console came the following errors :


    My HTML:

    01.<button (click)="viewer1.refreshReport()">Refresh</button>
    02.<button (click)="viewer1.setReportSource(rs)">setReportSource</button>
    03.<button (click)="temp = viewer1.getReportSource()">getReportSource</button>
    08.<tr-viewer #viewer1 *ngIf="reportSource"
    09.    [containerStyle]="viewerContainerStyle"
    10.    [reportServer]="creds"
    11.    [viewMode]="'PRINT_PREVIEW'"
    12.    [scaleMode]="'SPECIFIC'"
    13.    [scale]="1.0"
    14.    [reportSource] = "reportSource"


    What am I doing wrong? How can I call another report in the viewer?

  2. Silviya
    Silviya avatar
    331 posts

    Posted 25 Feb Link to this post

    Hi Frank,

    The error implies that we are trying to use getReportSource() method of undefined. This means that this.viewer is undefined at the moment when we call it. HOwever, getReportSource method is not necessary to be used when trying to update the report source of the viewer. 

    To update the report source, setReportSource method of the viewer can be used as following:
    <button (click)="viewer1.setReportSource({report: 'Samples/Invoice', parameters: {}})">Change Report Source</button>

    This method expects a JSON object with report(string) and parameters(JSON) properties - Angular Report Viewer MethodsSetReportSource() method will automatically reload the report (if any) into the view.

    Best Regards,
    Progress 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. Frank
    Frank avatar
    9 posts
    Member since:
    Feb 2019

    Posted 27 Feb in reply to Silviya Link to this post

    I found the mistake.
    The problem is / was the "*ngIf" directive.
    I have solved this now so that I check the "reportSource" before the component is loaded with the viewer, or not in case of errors.
    Was stupid of me.
Back to Top