Yes... But regarding my initial issue, I've found the problem.
If added this function down to the template (html one) and then everything ok.
function toString (data) {
return JSON.stringify(data);
}
thanks for your support anyway.
Yes... But regarding my initial issue, I've found the problem.
If added this function down to the template (html one) and then everything ok.
function toString (data) {
return JSON.stringify(data);
}
thanks for your support anyway.
Sorry @bjrmatos , how can I attach a file here? do I have to post a downloading link?
I'm no sure what should I add on my global helpers.js file...Could you please let me know?
Here's my script code:
const request = require('request');
async function getMaApi() {
const query = `{
monitorData(machineId:"8af00d441c99a48aba6666a4"){
trendValues(variables:["DT:addr_100","DT:addr_118","DT:addr_120"]since:1606842060000,until:1606842643000){
label
values{
timestamp
value
}
}
}
}`;
var postData = JSON.stringify({
query,
variables: null,
})
const options = {
url: 'https://ecostruxure-machine-advisor.se.app/daas/graphql',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer 9RfMdTD8Nh3aMd8xN9cRSr5SKwTV6fCTpyQcQcA5'
},
body: postData
};
function doRequest(options){
return new Promise(function(resolve,reject){
request(options, function(err,res,body){
resolve(body)
})
})
}
let response = await doRequest(options) //espera hasta que la promesa se resuelva
//return JSON.parse(response).data.me.username - Ejemplo para acceder a un campo de la respuesta
let trendValues = JSON.parse(response).data.monitorData.trendValues;
for (let tagIndex = 0 ; tagIndex < trendValues.length; tagIndex++){
for (let valueIndex = 0; valueIndex < trendValues[tagIndex].values.length; valueIndex ++){
let timestampValue = trendValues[tagIndex].values[valueIndex].timestamp
trendValues[tagIndex].values[valueIndex].timestamp = new Date(timestampValue*1000);
}
}
let formattedResponse = trendValues;
console.log(formattedResponse)
return formattedResponse;
}
//Antes de renderizar hay que hacer algo. función JSReport
async function beforeRender(req, res) {
req.data.trendValues = await getMaApi(); //en req.data añadimos toda la info que usaremos en el report. En machines
//hemos asociado toda la respuesta
}
const nodemailer = require('nodemailer');
async function afterRender(req, res) {
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
auth: {
user: 'mnogueracolome@outlook.com',
pass: '*****'
}
})
await transporter.sendMail({
from: "mnogueracolome@outlook.com",
to: "mnogueracolome@gmail.com",
subject: "Sending email from node.js",
text: "See the attached report",
html: "<b>See the attached report</b>",
/*attachments: [
{
filename: 'Report.pdf',
content: Buffer.from(res.content)
}],*/
})
}
Hello,
I'm just starting with jsreport (also with JS language in fact...) and I've got this error when running my document and I don't know what could be wrong:
Error while executing templating engine. Missing helper: "toString"
Error: Missing helper: "toString"
at Object.<anonymous> (C:\Users\jsreportapp\node_modules\handlebars\dist\cjs\handlebars\helpers\helper-missing.js:19:13)
at Object.wrapper (C:\Users\jsreportapp\node_modules\handlebars\dist\cjs\handlebars\internal\wrapHelper.js:15:19)
at Object.eval [as main] (eval at createFunctionContext (C:\Users\jsreportapp\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:262:23), <anonymous>:21:110)
at main (C:\Users\jsreportapp\node_modules\handlebars\dist\cjs\handlebars\runtime.js:208:32)
at ret (C:\Users\jsreportapp\node_modules\handlebars\dist\cjs\handlebars\runtime.js:212:12)
at ret (C:\Users\jsreportapp\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:519:21)
at C:\Users\jsreportapp\node_modules\jsreport-handlebars\lib\handlebarsEngine.js:33:20
at Object.base.apply (C:\Users\jsreportapp\node_modules\vm2\lib/contextify.js:469:32)
at evaluate-template-engine.js:1:64
at Script.runInContext (vm.js:143:18)
Let me know if you need me to paste my code.
Thanks!