Run Report from NodeJS Backend

Stimulsoft Reports.JS discussion
Post Reply
jclPTSG
Posts: 6
Joined: Fri Mar 02, 2018 1:00 pm

Run Report from NodeJS Backend

Post by jclPTSG »

So looking at Several Examples i still cannot grasp how to load a report from server side of a Node js application.

Could you please show an example?

I do know from example 6.

Code: Select all

// Creating new report
		var report = new Stimulsoft.Report.StiReport();
		// Loading report template
		report.loadFile("report/SimpleList.mrt");
		// Renreding report
		report.render();
		// Saving rendered report to JSON string
		var reportJson = report.saveDocumentToJsonString();
Does not load the mySQL data.

Also from example 5.

Code: Select all

var dataSet = new Stimulsoft.System.Data.DataSet("Demo");
// Load JSON data file from specified URL to the DataSet object
dataSet.readJsonFile("Demo.json");
// Remove all connections from the report template
report.dictionary.databases.clear();
// Register DataSet object
report.regData("Demo", "Demo", dataSet);
this will load data, but why do i have to delete the connection and re-add it? the connection string/query/fields are already in the mrt file.

any help will be nice.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Run Report from NodeJS Backend

Post by HighAley »

Hello.

The MySQL adapter is working in an async mode.
Please, try next code:

Code: Select all

        var report = new Stimulsoft.Report.StiReport();
        report.loadFile("report/WorkOrder.mrt");
        report.renderAsync(function(){
            var reportJson = report.saveDocumentToJsonString();
            res.end(reportJson);
        });
Thank you.
jclPTSG
Posts: 6
Joined: Fri Mar 02, 2018 1:00 pm

Re: Run Report from NodeJS Backend

Post by jclPTSG »

Sorry to say, but that still does not help.

From the previous post, there is no code that calleds the MySQL Adapter.

do you have a sample that you could show me that loads a report (in Node.js) that queries a mysql database and saves the report as a PDF?

that would help out alot.
cucr
Posts: 8
Joined: Thu Apr 28, 2016 6:56 am

Re: Run Report from NodeJS Backend

Post by cucr »

i have same problem,when i use render,i can not get data from the mrt file define.(i have define connection string in mrt file,connection test ok,when i preview,it can get data from database),but i use nodejs as backend,it can not get data from database.
when i use renderAsync to export pdf,pdf is exported,but when i open it,it show this file is broken and can not open.
report.renderAsync(function() {
// Export to PDF
var pdfData = report.exportDocument(Stimulsoft.Report.StiExportFormat.Pdf);

// Converting Array into buffer
var buffer = new Buffer(pdfData, "utf-8")

// File System module
var fs = require('fs');

// Saving string with rendered report in PDF into a file
fs.writeFileSync('report/SimpleList.pdf', buffer);
console.log("Rendered report saved into PDF-file.");
});
Lech Kulikowski
Posts: 6240
Joined: Tue Mar 20, 2018 5:34 am

Re: Run Report from NodeJS Backend

Post by Lech Kulikowski »

Hello,

Please check samples at the following link:
https://github.com/stimulsoft/Samples-J ... er/Node.js

Thank you.
jclPTSG
Posts: 6
Joined: Fri Mar 02, 2018 1:00 pm

Re: Run Report from NodeJS Backend

Post by jclPTSG »

Please see my first post on this.

The code that i posted came from those samples.
Lech Kulikowski
Posts: 6240
Joined: Tue Mar 20, 2018 5:34 am

Re: Run Report from NodeJS Backend

Post by Lech Kulikowski »

Hello,

Please check the following article:
https://www.stimulsoft.com/en/documenta ... tabase.htm

Thank you.
jclPTSG
Posts: 6
Joined: Fri Mar 02, 2018 1:00 pm

Re: Run Report from NodeJS Backend

Post by jclPTSG »

SO how do i use:

Code: Select all

StiOptions.WebServer.url
In Nodejs when i use:

Code: Select all

var Stimulsoft = require("stimulsoft-reports-js");
Lech Kulikowski
Posts: 6240
Joined: Tue Mar 20, 2018 5:34 am

Re: Run Report from NodeJS Backend

Post by Lech Kulikowski »

Hello,

In NodeJS samples, there is sample "04. Start SQL Adapters from Http Server", please check it.

Thank you.
Post Reply