miralemd / qlik-sse Goto Github PK
View Code? Open in Web Editor NEWQlik Server Side Extension in nodejs
License: MIT License
Qlik Server Side Extension in nodejs
License: MIT License
Error in the code evaluated by ScriptEval() will cause the server instance to terminate with the uncaught error. For example:
x.find()
where x is undefined of find() is not a method.
I've fixed this by adding try/catch here: https://github.com/RobWunderlich/qlik-sse/commit/91408d478ce4a153c7cdca3ba07dd96d32a7c1a8
Ideally, the value returned to Qlik would be a Qlik null, not the string "null" or "undefined". Is there some sse.DataType
for null?
In https://github.com/miralemd/qlik-sse/blob/master/examples/functions.md the aggregation example returns a result per bundle. If you have a large enough payload the SSE will return more than one row.
*Note I am using the qcb-qlik-sse which is built using your library and contains your example script.
Qlik Example
Result
Expected
I'm don't have much experience in Node.js so I'm sure there is a much better way to fix this. However, this is what I used to sum up the bundles before returning the result to Qlik.
const functionDefinition = function ProcessAllRows(request) {
let bundleNum = 0;
const bundleResult = [];
const rows = [];
request.on('data', (bundle) => {
console.log('ProcessAllRows: Bundle number ', ++bundleNum)
try {
let v = 0;
bundle.rows.forEach((row, index) => {
// console.log('ProcessAllRows: Row number ', index, row)
row.duals.forEach((dual) => {
if (!Number.isNaN(dual.numData)) {
v += dual.numData;
}
});
});
bundleResult.push(v)
}
catch (error) {
console.log(error)
}
});
request.on('end',() => {
let i = 0;
bundleResult.forEach((x, index) => {
i += x;
})
rows.push({
duals: [{ numData: i }],
});
console.log('ProcessAllRows: Bundles: ', bundleNum);
console.log('ProcessAllRows: Write rows: ', JSON.stringify(rows))
request.write({
bundleResult
});
});
}
For some reason I am unable to write information back within one of my functions. If I log the request before writing the data back I see the following which I suspect is my reason writable: false
Here is the function:
function GetAppMasterItems(request) {
request.on('data', async function (bundle) {
console.log(1);
let tmpItems = []
let finalItems = []
async function getData(row) {
return new Promise(async function (resolve, reject) {
let masterItems = [];
let appId = row.duals[0].strData;
let onlyQwikMaster = row.duals[1].strData;
let app = await global.openDoc(appId);
let allInfos = await app.getAllInfos();
for (var i = 0; i < allInfos.length; i++) {
if (allInfos[i].qType == 'measure') {
let measure = await app.getMeasure(allInfos[i].qId);
let measureLayout = await measure.getProperties();
if (onlyQwikMaster == 'true') {
if (typeof measureLayout.qMetaDef.masterId != 'undefined') {
masterItems.push(
[
measureLayout.qMetaDef.masterId,
"measure",
measureLayout.qMeasure.qDef,
measureLayout.qMeasure.qLabel,
measureLayout.qMetaDef.title,
measureLayout.qMetaDef.description,
measureLayout.qMeasure.coloring.baseColor.color,
appId
]
)
}
}
else {
masterItems.push(
[
measureLayout.qMetaDef.masterId,
"measure",
measureLayout.qMeasure.qDef,
measureLayout.qMeasure.qLabel,
measureLayout.qMetaDef.title,
measureLayout.qMetaDef.description,
measureLayout.qMeasure.coloring.baseColor.color,
appId
]
)
}
}
if (allInfos[i].qType == 'dimension') {
let dimension = await app.getDimension(allInfos[i].qId);
let dimensionLayout = await dimension.getProperties();
if (onlyQwikMaster == 'true') {
if (typeof dimensionLayout.qMetaDef.masterId != 'undefined') {
masterItems.push(
[
dimensionLayout.qMetaDef.masterId,
"dimension",
dimensionLayout.qDim.qFieldDefs[0],
dimensionLayout.qDim.qLabelExpression,
dimensionLayout.qDim.title,
dimensionLayout.qDim.descriptionExpression.qStringExpression.qExpr,
dimensionLayout.qDim.coloring.baseColor.color,
appId
]
)
}
}
else {
masterItems.push(
[
dimensionLayout.qMetaDef.masterId,
"dimension",
dimensionLayout.qDim.qFieldDefs[0],
dimensionLayout.qDim.qLabelExpression,
dimensionLayout.qDim.title,
dimensionLayout.qDim.descriptionExpression.qStringExpression.qExpr,
dimensionLayout.qDim.coloring.baseColor.color,
appId
]
)
}
}
}
resolve(masterItems)
})
}
for(var r = 0; r<bundle.rows.length;r++) {
let data = await getData(bundle.rows[r]);
tmpItems.push(data);
console.log(2);
}
var test = [];
for(var one = 0; one< tmpItems.length; one++) {
for(var two = 0; two < tmpItems[one].length;two++) {
for(var three = 0; three < tmpItems[one][two].length; three++) {
test.push({strDate: tmpItems[one][two][three]})
}
}
}
console.log(3, test);
console.log(4);
console.log(request);
request.write({ "rows": [{ "duals": [{ "strData": "Sucess!" }] }] });
})
}
The current npm package grpc
is logging deprecation warnings, might be time to migrate to @grpc/proto-loader
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.