3 Replies Latest reply: Apr 18, 2018 8:09 AM by Mathias Schindler RSS

    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);

       

      };

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

          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