Angular Report: ExportReport action not called.

Stimulsoft Reports.ANGULAR discussion
Post Reply
CyberCode
Posts: 2
Joined: Tue Jan 19, 2021 6:23 pm
Location: Florida, USA

Angular Report: ExportReport action not called.

Post by CyberCode »

Hello,
I have created a report page using the new Angular libraries and i've been running into some issues. The latest issue is the action ExportReport is never sent back to the server when trying to save the report in any format. Print Preview and Print works, but when I select PDF from the print dropdown, the client side makes the POST request that is not captured by my interceptors so the request gets sent to the UI endpoint and not the server endpoint.

The page allows the user to select a report from the drop down and apply filters. Once the user clicks 'Run Report', the filters and report filename is placed in the 'properties' of the request and parsed on the server side. Here is the function for 'Run Report'

Code: Select all

@ViewChild('stiViewer') stiViewer: StimulsoftViewerComponent;
// ...
// ... 
runReport(){
        this.reportViewerActive = true;
        this.reportSettings.template = this.activeSettings.selectedReport;

        this.applyFilters(); //takes the filters from the user and compiles this.reportSettings
        this.stiViewer.properties = this.reportSettings;
        this.stiViewer.requestUrl = `/api/Stimulsoft/${this.locationId}/{action}`;
        this.stiViewer.action='InitViewer';
        this.stiViewer.ngOnChanges(null); //triggers the stimulsoft component to update after assigning the url
    }
this is where the component/viewchild is defined in the html template. [note] i know the url is missing from this, it is intentional so the report UI does not populate until the user clicks 'run report'

Code: Select all

         <div class="flex-item flex-grow" style="min-height: 100%;">
            <stimulsoft-viewer-angular 
                #stiViewer
                height="75vh" ></stimulsoft-viewer-angular>
        </div>
Here is the server side that handles the client requests

Code: Select all

        [HttpPost("{location}/InitViewer")]
        public IActionResult InitViewer([FromRoute]int location)
        {

            var requestParams = StiAngularViewer.GetRequestParams(this);
            var options = new StiAngularViewerOptions();
            options.Actions.ViewerEvent = "ViewerEvent";
            options.Appearance.ScrollbarsMode = true;
            options.Exports.ShowExportDialog = false;
            options.Server.CacheMode = StiServerCacheMode.ObjectSession;
            StiAngularViewer.CacheHelper = new ScaleitStiCache();

            return StiAngularViewer.ViewerDataResult(requestParams, options);

        }

        [HttpPost("{location}/ViewerEvent")]
        public IActionResult ViewerEvent([FromRoute]int location, [FromForm]string properties)
        {

            var requestParams = StiAngularViewer.GetRequestParams(this);
	    if (requestParams.Action == StiAction.GetReport)
            {
                
                var reportProperties = this.parseProperties(properties);


                var stiReport = this.getTemplate(location, reportProperties);
                stiReport = this.setTemplateConnection(location, stiReport);
                stiReport = this.setTemplateVariables(stiReport, reportProperties);

                return StiAngularViewer.GetReportResult(this, stiReport);
            }
            
            return StiAngularViewer.ProcessRequestResult(this);
        }
I have placed breakpoints on the ViewerEvent to inspect the received actions, I also inspected the web traffic using Fiddler and I do not see any requests for exporting from the client. In an attempt to remedy the print to pdf action issue, I tried including the baseurl in the this.stiViewer.requestUrl statement, but this caused another error to prompt stating 'unable to read 'Method' of null' and I wasn't able to run the report at all.

front end versions
-initial
-stimulsoft-reports-js 2020.5.1
-stimulsoft-viewer-angular: 2020.5.1-b
-current
-stimulsoft-reports-js 2021.1.1
-stimulsoft-viewer-angular:2021.1.1

Server version
-Stimulsoft.Reports.Angular.NetCore 2020.5.1

Please let me know if you need any additional information, any help would be great.
CyberCode
Posts: 2
Joined: Tue Jan 19, 2021 6:23 pm
Location: Florida, USA

Re: Angular Report: ExportReport action not called.

Post by CyberCode »

I found the solution to my post.
The issue was I was relying on my interceptor for Angular's HttpClient (which had a bug of its own, see below) to insert the base url (in this case, http://localhost:55853) into the requests. The interceptor works only when HttpClient is used and it appears that the Stimulsoft libraries doesn't use HttpClient to send requests for exporting or printing to pdf.

The solution, I imported my environment object into the component and added the base url into the stiViewer.requestUrl statement. This allowed me to have a single url assignment for any environment based on how the Angular application is configured at build time.

Code: Select all


    runReport(){
        this.reportViewerActive = true;
        this.reportSettings.template = this.activeSettings.selectedReport;

        this.applyFilters();
        this.stiViewer.properties = this.reportSettings;
        this.stiViewer.requestUrl = `${environment.apiUrl}/api/Stimulsoft/${this.locationId}/{action}`;
        this.stiViewer.action='InitViewer';
        this.stiViewer.ngOnChanges(null);
    }
I tried including the baseurl in the this.stiViewer.requestUrl statement, but this caused another error to prompt stating 'unable to read 'Method' of null' and I wasn't able to run the report at all.
This was caused by a bug in my Interceptor. Instead of passing the original request when a base is already present, I was passing a newly created request with no information in it. Once I fixed it by passing the original request, this error was resolved.
Lech Kulikowski
Posts: 6471
Joined: Tue Mar 20, 2018 5:34 am

Re: Angular Report: ExportReport action not called.

Post by Lech Kulikowski »

Hello,

Thank you for the information.
bdayakarreddy
Posts: 7
Joined: Wed Jan 25, 2023 6:20 am

Re: Angular Report: ExportReport action not called.

Post by bdayakarreddy »

Hi i am using stimulsoft angular libraries with .net core. i am unable to export the report on the client side i am getting not authenticated error.
Lech Kulikowski
Posts: 6471
Joined: Tue Mar 20, 2018 5:34 am

Re: Angular Report: ExportReport action not called.

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
Post Reply