Page 1 of 1

Load a Report from a string and not from a file

Posted: Thu Feb 09, 2023 3:42 pm
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);
                }

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

Posted: Thu Feb 09, 2023 4:08 pm
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 2924 times

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

Posted: Fri Feb 10, 2023 8:09 am
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?

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

Posted: Fri Feb 10, 2023 8:09 pm
by Lech Kulikowski
Hello,

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

Thank you.

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

Posted: Fri Feb 17, 2023 5:42 pm
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.

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

Posted: Fri Feb 17, 2023 11:29 pm
by Lech Kulikowski
Hello,

Thank you for the information.