Custom server side script result is not rendering.
-
i am using custom server side script to fetch data from remote REST API,
i am getting results from the rest api, but this is not binding to the report.
the report still renders are sample data.below is the custom script.
i am new to javascript and jsreports, please help me
var http = require('http');
var request = require('request');function beforeRender(req, res, done) {
console.log('Calculating item ' + '; you should see this message in debug run')
var options = {
url: 'http://nsgeoviewerapistaging-env.us-east-1.elasticbeanstalk.com/api/v1/getreportsdata',
method: 'POST',
form: {
'servicename': 'riversidecourts',
'reportname': 'Investigator Report',
'reporttag': 'inv',
'stdate': '2016-01-01',
'eddate': '2017-01-01'
}
}
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
// Print out the response body
var obj = JSON.parse(body);
res.data = obj;
console.log('response ---'+ body )
//console.log(obj.invSummary[1].name)
done();
}
});
}
below is the debug log.
+0 Starting rendering request 1390
+1 Rendering template {shortid:H1v3PF70x, recipe:phantom-pdf,engine:handlebars}
+1 Inline data specified.
+1 Executing script rk07o82Ax
+209 Calculating item ; you should see this message in debug run
+256 response ---{"invSummary":[{"name":"Melissa Armstrong","totalcases":"25"},{"name":"Pam Tharaldson","totalcases":"154"},{"name":"Temecula Court","totalcases":"12"}],"invDetails":[{"zip_code":"95017","region":"Davenport","overallcases":0,"name":"Melissa Armstrong","population":0,"totalcases":"0"},{"zip_code":"92882","region":"Corona","overallcases":5,"name":"Melissa Armstrong","population":70676,"totalcases":"41"},{"zip_code":"92530","region":"Lake Elsinore","overallcases":20,"name":"Melissa Armstrong","population":53606,"totalcases":"33"},{"zip_code":"92883","region":"Corona","overallcases":0,"name":"Melissa Armstrong","population":32167,"totalcases":"20"},{"zip_code":"92880","region":"Corona","overallcases":87,"name":"Pam Tharaldson","population":63696,"totalcases":"25"},{"zip_code":"92860","region":"Norco","overallcases":0,"name":"Pam Tharaldson","population":27091,"totalcases":"28"},{"zip_code":"92879","region":"Corona","overallcases":0,"name":"Pam Tharaldson","population":47452,"totalcases":"47"},{"zip_code":"92570","region":"Perris","overallcases":0,"name":"Pam Tharaldson","population":56738,"totalcases":"40"},{"zip_code":"92505","region":"Riverside","overallcases":67,"name":"Pam Tharaldson","population":49319,"totalcases":"39"},{"zip_code":"92881","region":"Corona","overallcases":12,"name":"Temecula Court","population":33490,"totalcases":"27"},{"zip_code":"92503","region":"Riverside","overallcases":0,"name":"Temecula Court","population":94431,"totalcases":"65"},{"zip_code":"92504","region":"Riverside","overallcases":0,"name":"Temecula Court","population":53772,"totalcases":"44"}]}
+256 {"invSummary":[{"name":"Melissa Armstrong","totalcases":"25"},{"name":"Pam Tharaldson","totalcases":"154"},{"name":"Temecula Court","totalcases":"12"}],"invDetails":[{"zip_code":"95017","region":"Davenport","overallcases":0,"name":"Melissa Armstrong","population":0,"totalcases":"0"},{"zip_code":"92882","region":"Corona","overallcases":5,"name":"Melissa Armstrong","population":70676,"totalcases":"41"},{"zip_code":"92530","region":"Lake Elsinore","overallcases":20,"name":"Melissa Armstrong","population":53606,"totalcases":"33"},{"zip_code":"92883","region":"Corona","overallcases":0,"name":"Melissa Armstrong","population":32167,"totalcases":"20"},{"zip_code":"92880","region":"Corona","overallcases":87,"name":"Pam Tharaldson","population":63696,"totalcases":"25"},{"zip_code":"92860","region":"Norco","overallcases":0,"name":"Pam Tharaldson","population":27091,"totalcases":"28"},{"zip_code":"92879","region":"Corona","overallcases":0,"name":"Pam Tharaldson","population":47452,"totalcases":"47"},{"zip_code":"92570","region":"Perris","overallcases":0,"name":"Pam Tharaldson","population":56738,"totalcases":"40"},{"zip_code":"92505","region":"Riverside","overallcases":67,"name":"Pam Tharaldson","population":49319,"totalcases":"39"},{"zip_code":"92881","region":"Corona","overallcases":12,"name":"Temecula Court","population":33490,"totalcases":"27"},{"zip_code":"92503","region":"Riverside","overallcases":0,"name":"Temecula Court","population":94431,"totalcases":"65"},{"zip_code":"92504","region":"Riverside","overallcases":0,"name":"Temecula Court","population":53772,"totalcases":"44"}]}
+259 Resources not defined for this template.
+259 Rendering engine handlebars
+384 Compiled template not found in the cache, compiling
+417 Replaced images ["RiversideCourts"]
+417 Executing recipe phantom-pdf
+532 Converting in dedicated phantomjs 1.9.8
+535 Request file:///%2Ftmp%2Fjsreport-temp%2F4da22d70-29ab-11e7-86a6-4747bdb16403html.html
+535 Request file://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css
+536 Request http://code.jquery.com/jquery-1.11.0.min.js
+536 Request http://cdnjs.cloudflare.com/ajax/libs/flot/0.8.1/jquery.flot.min.js
+536 Request http://cdnjs.cloudflare.com/ajax/libs/flot/0.8.1/jquery.flot.categories.min.js
+576 Request data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAABeCAYAAAAKYQnFAAAAAXNSR0IArs4c6QAAAARnQU...
+708 phantom-pdf recipe finished with 2 pages generated
+708 Skipping storing report.
+710 Rendering request finished 1390
-
It looks the problem is that you set
res.data
instead ofreq.data
See the documentation https://jsreport.net/learn/scripts
Tip: Use markdown syntax for code highlighting https://help.github.com/articles/creating-and-highlighting-code-blocks/
-
thank you very much, yes it was mistake.