why reportData is undefined?
-
hi,
I have report that gets data from api. and sets the value to req.data.reportData.
function beforeRender(req, res, done) { var postRequest = (postOptions.port == 443 ? https : http).request(postOptions, (result) => { var str = ''; result.setEncoding('utf8'); result.on('data', (b) => str += b); result.on('end', () => { req.data.reportData = JSON.parse(str); done(); }) });
I want to use that value in normal javascript. but reportData is undefined.
<script> document.querySelector("#theElement").innerHTML = reportData.theProp; </script>
what am I missing here?
there were other reports that I copied having this usage {{{toJSON reportData.theProp}}}
but I want to be able to use directly from js. how can I do that?
-
it turned out I need to add helper.js file near the report template file.
and after call like this.
var reportData = {{{toJSON reportData}}};
-