Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
nil-1995
New Contributor II

Can I get values from a table via a WebSocket?

I created a table in Qlik Sense with dimensions and measures. Also one measure has an expression. Why I can't see the expression on console (another fillds I can see)? How to get the content of the table using Websocket? I want to show the table using only table's ID.

//connection

var WebSocket = require('ws');

var fs = require('fs');

var certificates = {

     cert: fs.readFileSync('./certificats/client.pem'),

    key: fs.readFileSync('./certificats/client_key.pem'),

    root: fs.readFileSync('./certificats/root.pem')

};

var ws = new WebSocket("wss://server.domen:9999/app/", {

     ca: certificates.root,

     cert: certificates.cert,

     key: certificates.key,

     headers: {

          'X-Qlik-User':  'UserDirectory=internal; UserId=sa_engine'

     }

});

//queries

ws.onopen = function (event) {

         var OpenDoc = {

          "method": "OpenDoc",

          "handle": -1,

          "params": [

          "AppID"

          ],

          "outKey": -1,

          "id": 1

}

var GetObject = {

     "handle": 1,

     "method": "GetObject",

     "params": {

     "qId": "ObjectID"

     },

     "outKey": -1,

     "id": 3

}

var GetLayout = {

     "handle": 2,

     "method": "GetLayout",

     "params": {},

     "outKey": -1,

     "id": 4

}

ws.send(JSON.stringify(OpenDoc));

ws.onmessage = function (event) {

   var response = JSON.parse(event.data);

   console.log(response); 

};

ws.send(JSON.stringify(GetObject));

ws.onmessage = function (event) {

   var response = JSON.parse(event.data);

   console.log(response); 

};

setTimeout(function() { ws.send(JSON.stringify(GetFullPropertyTree));

     ws.onmessage = function (event) {

     var response = JSON.parse(event.data);

     var dimensionInfo = response.result.qLayout.qHyperCube.qDimensionInfo;

     var measureInfo = response.result.qLayout.qHyperCube.qMeasureInfo;

     dimensionInfo.forEach(function(item, dimensionInfo) {

          console.log(item.qFallbackTitle);

     })

     measureInfo.forEach(function(item, measureInfo) {

          console.log(item.qFallbackTitle);

})

    

} }, 2000);

};

3 Replies
m_schindler
Contributor II

Re: Can I get values from a table via a WebSocket?

Hello Илья,

I think you made a pasting error (you create a variable called GetLayout and then later stringify a variable GetFullPropertyTree) but that shouldnt really matter.

I always use the Engine-API-Explorer for these kind of things because it is very helpful (/dev-hub/engine-api-explorer):dev-hub.png

When looking at the result of GetFullPropertyTree we can see that there is no property named "qMeasureInfo" inside the qHyperCubeDef, only a property called "qMeasures".Inside the individual measure's objects is another property called qDef which in turn contains the expression used for this measure.

To find the correct paths / properties just play around with the engine-api-explorer. You can also check out Qliks enigma.js which should simplify the communication with qlik sense


Cheers,


Mathias

nil-1995
New Contributor II

Re: Can I get values from a table via a WebSocket?

Thanks a lot!

Can I get field's values in this way? I can calculate measures but EvaluateEx function returns only one result. I want to calculate measures for all rows. Is it possible to get rows?

m_schindler
Contributor II

Re: Can I get values from a table via a WebSocket?

You can get values by using a hypercube (which you can construct using a HyperCubeDefinition).

For a GetObject-handle you can probably use something like this:

{

"method": "GetHyperCubeData",

"params": {

"qPath": "/qHyperCubeDef",

"qPages": [

{

"qLeft": 0,

"qTop": 0,

"qWidth": 99,

"qHeight": 99

}

]

}

Mathias

Community Browser