Load a Report from a string and not from a file

Stimulsoft Reports.JS discussion
Post Reply
Flo
Posts: 7
Joined: Fri Jul 16, 2021 7:18 am

Load a Report from a string and not from a file

Post by Flo »

I would like to save my report data in a database. However, when I try to load a report using a string, this is not possible, I can't find any function that can do this.

Code: Select all

          var report = new Stimulsoft.Report.StiReport();
                var n = Stimulsoft.System.Guid.newGuid().toString().substr(0, 8);
                if ($.IsJson(reportfile)) {
                    report.load(reportfile); //which function do I have to use?
                } else {
                    report.loadFile(reportfile + "?n=" + n);
                }
Flo
Posts: 7
Joined: Fri Jul 16, 2021 7:18 am

Re: Load a Report from a string and not from a file

Post by Flo »

I use Version: 2021.3.5

In the attachement you can see the error which I get when I use the "load" function:
error.png
error.png (5.91 KiB) Viewed 1458 times
Flo
Posts: 7
Joined: Fri Jul 16, 2021 7:18 am

Re: Load a Report from a string and not from a file

Post by Flo »

The problem was with the data, now the reports can be loaded by string.
But now I have another problem, when I load a report with the ".load" function, it creates a new file for me separately every time, can I work around this somehow?
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Load a Report from a string and not from a file

Post by Lech Kulikowski »

Hello,

Sorry, maybe we did not exactly understand your question. Could you explain your issue in more detail?

Thank you.
ShawnJS
Posts: 2
Joined: Fri Feb 17, 2023 5:32 pm

Re: Load a Report from a string and not from a file

Post by ShawnJS »

I am doing this in my project. Below is my Load Report function.

Code: Select all

export const LoadReport = (reportData,reportName,dataSets) => {
	const report = Stimulsoft.Report.StiReport.createNewReport();
	report.load(reportData.reportData);
	if (reportName) {
		report.reportName = reportName;
	}
	report.dictionary.databases.clear();
	reportData.dataSourcesCSV
		.split(',')
		.forEach(ds => {
			try {
				const dataSet = new Stimulsoft.System.Data.DataSet(ds);
				dataSet.readJson(dataSets[ds]);
				report.regData(ds, ds, dataSet);
			} catch (dsError) {
				throw new Error("Error Loading DataSet " + ds);
			}
		});
	return report
}
reportData.reportData is the JSON string of JSON Report Template mrt file.
Lech Kulikowski
Posts: 6238
Joined: Tue Mar 20, 2018 5:34 am

Re: Load a Report from a string and not from a file

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply