info+0Render request 52 queued for execution and waiting for availible worker
info+23Starting rendering request 52 (user: admin)
info+0Rendering template { name: Daily_State_Balance, recipe: html-to-xlsx, engine: handlebars, preview: true }
debug+2Data item not defined for this template.
debug+4Executing script prod_daily_state_balance (beforeRender)
warn+351Error when processing render request 52 Error when evaluating custom script /Prod11/prod_daily_state_balance
Unable to perform operation because a connection was never established. ClientError: Unable to perform operation because a connection was never established.
at createError (/home/ubuntu/jsreportapp/node_modules/snowflake-sdk/lib/errors.js:535:15)
at Object.exports.createClientError (/home/ubuntu/jsreportapp/node_modules/snowflake-sdk/lib/errors.js:350:10)
at /home/ubuntu/jsreportapp/node_modules/snowflake-sdk/lib/services/sf.js:977:21
at processTicksAndRejections (node:internal/process/task_queues:78:11)
code
// Use the "beforeRender" or "afterRender" hook
// to manipulate and control the report generation
async function beforeRender(req, res) {
// Load the Snowflake Node.js driver.
var snowflake = require('snowflake-sdk');
// Create a Connection object that we can use later to connect.
var connection = snowflake.createConnection({
account: 'gm36774.eu-west-2',
username: '*********',
password: '*********'
});
const statement = connection.execute({
sqlText: 'select STATE, STATE_CREDITS, STATE_ACTUAL_CASH, STATE_UNREVEALED, STATE_CUSTOMER_FUNDS FROM SUPERDRAFT_PROD.SD_REPORTS.VW_DAILY_STATE_BALANCE_SDPRO;'
});
const rows = []
const rowsStream = statement.streamRows()
await new Promise((resolve, reject) => {
rowsStream.on('data', function (row) {
rows.push(row)
})
rowsStream.on('end', function (row) {
if (row) {
rows.push(row)
}
})
rowsStream.on('error', function (streamError) {
reject(streamError)
})
})
req.data.detail = rows
}