2 Replies Latest reply: Oct 10, 2017 2:10 AM by Joel Wikström RSS

    Fail to reload Qlik Sense dashboard app through engine api and websocket

    Joel Wikström



      I have created a Qlik Sense Desktop applikation and I want update it every five minutes and show it as a dashboard in a web page as an embedded iFrame configured in the Single configurator.


      I have made a script that connects to the engine api through a web socket and sends openDoc, doReload and saveObject every five minutes. The script runs without errors. The script log is generated, the qvf file is updated and csv-file is exported correctly at the end of the script but the data in the application is not updated.


      In the script I create a variable as let vDate = now(); which I show in a text box and that value is updated but nothing else in the GUI. My only explanation to this is that the data in the application is never updated when the script runs.


      How could I script the reload of an application through the eninge API?

      Do I need to save the data after reloading the application?


      Below is my html page embedding the dashboard with a script reloading the application every five minutes:




          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

          <script type="text/javascript">


      //Engine API request bodies

      var openDoc = {

        "method": "OpenDoc",

        "handle": -1,

        "params": [



        "outKey": -1,

        "id": 2



      var doReload = {

        "handle": 1,

        "method": "DoReload",

        "params": {

          "qMode": 0,

          "qPartial": false,

          "qDebug": false




      var saveObjects = {

        "handle": 1,

        "method": "SaveObjects",

        "params": {},

        "outKey": -1,

        "id": 4




      //Helper function for logging

      function logga(text)


      var time = new Date();

      var timeStr = time.toLocaleTimeString();

      var str = timeStr + " " + text;





      //Function that prepares a function that communicates with Qlik throuh the engine API

      //Sends msg to the websocket ws and applies next once a responce is received.

      //No error detection implemented

      function wsCommand(ws, msg, name, next) {

        return function (evt) {


          logga(name + " message is sent..."  + JSON.stringify(msg, null, 2));



          ws.onmessage = function (evt) {

            var received_msg = evt.data;

            logga(name + "Message is received: " + JSON.stringify(received_msg, null, 2));







      //Functionality to reload the whole page and not just the iFrame in order to clear console log

      var reloadCounter = 0;



      //Function to refresh the dashboard as the last step in the command chain

      function wrapUp(ws) {

        return function() {



          reloadCounter += 1;

          if(reloadCounter < 10) {

            logga("Refresh count " + reloadCounter);


          } else {

            window.location.reload() //Reload the whole page and not just the iFrame in order to clear console log






      function reloadAndRefresh() {

        if ("WebSocket" in window) {

           logga("WebSocket is supported by your Browser!");



           var ws = new WebSocket("ws://localhost:4848/app");



           ws.onmessage = function(evt) {

             var received_msg = evt.data;

             logga(name + "Message is received: " + JSON.stringify(received_msg, null, 2));



             //1. open doc -> 2. doReload -> 3. saveObjects

             var saveObjectsCmd = wsCommand(ws, saveObjects, 'saveObjects', wrapUp(ws));

             var doReloadCmd = wsCommand(ws, doReload, 'doReload', saveObjectsCmd);

             var openDocCmd = wsCommand(ws, openDoc, 'openDoc', doReloadCmd);







           ws.onclose = function() {

              logga("Connection is closed...");




           window.onbeforeunload = function(event) {





        else {

           // The browser doesn't support WebSocket

           logga("WebSocket NOT supported by your Browser!");





          //Update the frame with the dashboard. Add a new IFrame instead of refresh due to cross browsing issues

          function refreshDashboard() {

            var d = $("#dashboard");






















          <div id="dashboard"></div>



          <script type="text/javascript">



            setInterval(reloadAndRefresh, 5 * 60 * 1000 );