Errors in the async merged report

Stimulsoft Reports.JS discussion
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Errors in the async merged report

Post by Mateus Garrido Kern » Fri Jul 10, 2020 6:01 pm

Hi,

I'm trying some problems when I merged three reports.

Attachment Screenshot_1:
The times when the report finishes loading it displays the error "cannot read property 'pageNumbers' of null"

Attachment Screenshot_2 and Screenshot_3:
When I go to the third or fourth page of the report, the following errors appear: "Cannot read property 'name' of undefined" and Cannot read property 'sortingEnabled' of undefined

I think it has something to do with the merged report loading the pages of the other reports asynchronously.

Thank you for attention
Attachments
Screenshot_3.png
Cannot read property 'sortingEnabled' of undefined
Screenshot_3.png (92.28 KiB) Viewed 1409 times
Screenshot_2.png
Cannot read property 'name' of undefined
Screenshot_2.png (61.84 KiB) Viewed 1409 times
Screenshot_1.png
cannot read property 'pageNumbers' of null
Screenshot_1.png (39.49 KiB) Viewed 1409 times
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Lech Kulikowski
Posts: 3468
Joined: Tue Mar 20, 2018 5:34 am

Re: Errors in the async merged report

Post by Lech Kulikowski » Tue Jul 14, 2020 11:10 am

Hello,

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

Thank you.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Errors in the async merged report

Post by Mateus Garrido Kern » Wed Jul 15, 2020 1:09 pm

Hi Lech,

I sent an email to support@stimulsoft with the project with errors and it's generated the number request 3165067.

Thank you
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Lech Kulikowski
Posts: 3468
Joined: Tue Mar 20, 2018 5:34 am

Re: Errors in the async merged report

Post by Lech Kulikowski » Wed Jul 15, 2020 2:39 pm

Hello,

Thank you. We will let you know about the result.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Errors in the async merged report

Post by Mateus Garrido Kern » Mon Jul 20, 2020 1:10 pm

Hello, any solution to this problem?
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Lech Kulikowski
Posts: 3468
Joined: Tue Mar 20, 2018 5:34 am

Re: Errors in the async merged report

Post by Lech Kulikowski » Thu Jul 23, 2020 7:41 am

Hello,

We are working on the problem, we will let you know about the result.

Thank you.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Errors in the async merged report

Post by Mateus Garrido Kern » Fri Aug 21, 2020 7:50 pm

Hello,

I received a response from Aleksey Andreyanov by email, written:

"When you render the reports you are using async methods but don't wait for the end of the rendering.
There are no rendered pages when you pass the report to the Viewer.
You should get the report inside the response function. "

What is the Report's response function?
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Errors in the async merged report

Post by Mateus Garrido Kern » Mon Aug 24, 2020 12:38 pm

Hello,

The answer I received is attached: "Screenshot_1.png".

It is about 3165067 request, and was answered on the August 04, 2020.

What is the Report's response function?

Thank you.
Attachments
Screenshot_1.png
Screenshot_1.png (20.79 KiB) Viewed 1140 times
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
HighAley
Posts: 8368
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Errors in the async merged report

Post by HighAley » Wed Aug 26, 2020 2:23 pm

Hello,

You call the renderAsync() function and try to do something with the report right after calling it.
You should do it like in this sample :

Code: Select all

report.renderAsync(function () {
     var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
     var service = new Stimulsoft.Report.Export.StiPdfExportService();
     var stream = new Stimulsoft.System.IO.MemoryStream();
     for (var index = 1; index <= report.renderedPages.count; ++index) {
          settings.pageRange = new Stimulsoft.Report.StiPagesRange(Stimulsoft.Report.StiRangeType.Pages, index.toString());
          service.exportTo(report, stream, settings);
          var data = stream.toArray();
          var fileName = index;
          Object.saveAs(data, fileName + ".pdf", "application/pdf");
     }
});
Thank you.
Mateus Garrido Kern
Posts: 29
Joined: Wed Sep 04, 2019 5:19 pm
Location: Curitiba/PR (Brazil)

Re: Errors in the async merged report

Post by Mateus Garrido Kern » Wed Aug 26, 2020 2:59 pm

Hello,

I already use the renderAsync method, but I also use the merge between reports, where I intend to merge it only when the user wishes, follow the code:

Code: Select all

import { Component, OnInit  } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { environment } from '../../../../../environments/environment';

declare var Stimulsoft: any;

@Component({
	selector: 'app-report-cash-desk-book',
	template: `<div id="viewerContent"></div>`
})

export class ReportCashDeskBookComponent implements OnInit {
	options: any = new Stimulsoft.Viewer.StiViewerOptions();
	viewer: any = new Stimulsoft.Viewer.StiViewer(this.options, 'StiViewer', false);
	baseUrl: string;
	companyId: string;
	dateStart: string;
	dateFinish: string;
	separateByMonth: string;
	cashDeskAccount: string;
	bookNumber: string;
	dateEmission: string;
	dateCloseFiscalYear: string;
	showOpenCloseTerms: boolean;

	constructor(private activatedRoute: ActivatedRoute) { }

	ngOnInit() {
		this.baseUrl = environment.apiUrl;
		this.activatedRoute.queryParams.subscribe(params => {
			this.companyId = params['companyId'];
			this.dateStart = params['dateStart'];
			this.dateFinish = params['dateFinish'];
			this.separateByMonth = params['separateByMonth'];
			this.cashDeskAccount = params['cashDeskAccount'];
			this.bookNumber = params['bookNumber'];
			this.dateEmission = params['dateEmission'];
			this.dateCloseFiscalYear = params['dateCloseFiscalYear'];
			this.showOpenCloseTerms = params['showOpenCloseTerms'] === 'true' ? true : false;
		});

		let reportOpen;
		let reportCashDeskBook;
		let reportClose;
		let dbOpen;
		let dbCashDeskBook;
		let dbClose;

		reportCashDeskBook = Stimulsoft.Report.StiReport.createNewReport();
		reportCashDeskBook.loadFile('../../../../../assets/reports/reportCashDeskBook.mrt');
		reportCashDeskBook.isAsync = true;

		dbCashDeskBook = reportCashDeskBook.dictionary.databases.getByName('CashDeskBook');

		dbCashDeskBook.pathData = environment.apiUrl + '/v1/reports/cash-desk-book?' +
		'companyId=' + this.companyId + '&dateStart=' + this.dateStart + '&dateFinish=' +
		this.dateFinish + '&separateByMonth=' + this.separateByMonth;

		if (this.cashDeskAccount !== null && this.cashDeskAccount !== undefined) {
			dbCashDeskBook.pathData += '&cashDeskAccount=' + this.cashDeskAccount;
		}

		const reportMerge = new Stimulsoft.Report.StiReport();
		reportMerge.reportUnit = reportCashDeskBook.reportUnit;
		reportMerge.renderAsync();
		reportMerge.renderedPages.clear();

		if (this.showOpenCloseTerms) {
			reportOpen = Stimulsoft.Report.StiReport.createNewReport();
			reportOpen.loadFile('../../../../../assets/reports/ReportOpenCloseTerm.mrt');

			dbOpen = reportOpen.dictionary.databases.getByName('JSON');

			dbOpen.pathData = this.baseUrl + 'v1/reports/open-cash-desk-book-term?companyId=' +
			this.companyId + '&dateStart=' + this.dateStart + '&dateFinish=' + this.dateFinish + 
			'&separateByMonth=' + this.separateByMonth + '&bookNumber=' + this.bookNumber + '&dateEmission=' + 
			this.dateEmission + '&dateCloseFiscalYear=' + this.dateCloseFiscalYear;

			reportClose = Stimulsoft.Report.StiReport.createNewReport();
			reportClose.loadFile('../../../../../assets/reports/ReportOpenCloseTerm.mrt');

			dbClose = reportClose.dictionary.databases.getByName('JSON');

			dbClose.pathData = this.baseUrl + 'v1/reports/close-cash-desk-book-term?companyId=' +
			this.companyId + '&dateStart=' + this.dateStart + '&dateFinish=' + this.dateFinish + 
			'&separateByMonth=' + this.separateByMonth + '&bookNumber=' + this.bookNumber + '&dateEmission=' + 
			this.dateEmission + '&dateCloseFiscalYear=' + this.dateCloseFiscalYear;

			reportOpen.onBeginProcessData = function (event) {
				event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
			};

			reportOpen.renderAsync(function () {
				for (let index = 0; index < reportOpen.renderedPages.count; ++index) {
					reportMerge.renderedPages.add(reportOpen.renderedPages.getByIndex(index));
				}
			});
		}

		reportCashDeskBook.onBeginProcessData = function (event) {
			event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
		};

		reportCashDeskBook.renderAsync(function () {
			for (let index = 0; index < reportCashDeskBook.renderedPages.count; ++index) {
				reportMerge.renderedPages.add(reportCashDeskBook.renderedPages.getByIndex(index));
			}
		});

		if (this.showOpenCloseTerms) {
			reportClose.onBeginProcessData = function (event) {
				event.headers.push({key: 'Authorization', value: 'Bearer ' + localStorage.getItem('token')});
			};

			reportClose.renderAsync(function () {
				for (let index = 0; index < reportClose.renderedPages.count; ++index) {
					reportMerge.renderedPages.add(reportClose.renderedPages.getByIndex(index));
				}
			});
		}

		reportMerge.renderedPages.list.forEach(function(page, i, arr) {
			const pagination = page.components.getByName('Pagination');
			if (pagination) {
				pagination.text = 'Page ' + (i + 1) + ' of ' + reportMerge.renderedPages.count;
			}

			const centralText = page.components.getByName('CentralText');
			if (centralText) {
				centralText.text = centralText.text.replace(/{TotalPages}/gi, '' + reportMerge.renderedPages.count);
			}
		});

		this.options.appearance.fullScreenMode = true;
		this.options.toolbar.displayMode = Stimulsoft.Viewer.StiToolbarDisplayMode.Separated;

		this.viewer.report = reportMerge;
		this.viewer.renderHtml("viewerContent");
	}

}
And keep showing me the same mistake! Any solution for this case?
Mateus Garrido Kern
Email: desenv5.digibyte@outlook.com
Post Reply