Qlik Community

Ask a Question

Integration, Extension & APIs

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

Announcements
QlikWorld Online 2021, May 10-12: Our Free, Virtual, Global Event REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
JoanPedro2
Contributor
Contributor

Erro with Engine API - Qlik Sense Desktop

I need to make a interval refresh on my data table. But, the method doReload not works. On Engine API Explorer i receive invalid Status for doReload call in Doc. 

And, in Javascript i receive the comming Object: 

{
jsonrpc: '2.0',
id: 0,
error: {
code: -32602,
parameter: 'Invalid handle',
message: 'Invalid Params'
}
}

I able to call DOC and receive:

{
jsonrpc: '2.0',
method: 'OnConnected',
params: { qSessionState: 'SESSION_ATTACHED' }
}

{
jsonrpc: '2.0',
id: 2,
result: {
qReturn: {
qType: 'Doc',
qHandle: 1,
qGenericId: 'C:\\Users\\LDXNT25\\Documents\\Qlik\\Sense\\Apps\\DBTesting.qvf'
}
}

My Javascript code is:

const WebSocket = require('ws')

module.exports = app => {

    function Repeating() {
        var ws = new WebSocket("ws://localhost:4848/app/C%3A%5CUsers%5CLDXNT25%5CDocuments%5CQlik%5CSense%5CApps%5CDBTesting.qvf")

        var openingDoc = {
            "jsonrpc": "2.0",
            "id": 2,
            "method": "OpenDoc",
            "handle": -1,
            "params": [
                "C:\\Users\\LDXNT25\\Documents\\Qlik\\Sense\\Apps\\DBTesting.qvf"
            ]
        }

        var doReloading = {
            "handle": 1,
            "method": "DoReload",
            "params": {
                "qMode": 0,
                "qPartial": false,
                "qDebug": false
            }
        }

        ws.onopen = function(e) {
            console.log("Sending to server");
            ws.send(JSON.stringify(openingDoc))
            ws.send(JSON.stringify(doReloading))

        }

        ws.onmessage = function(event) {
            console.log(JSON.parse(event.data))
        }
    }

    setInterval(() => {
        Repeating()
    }, 25000);

}

 

The question: What the erro? Im on Limited Account (30days)

2 Replies
yko
Employee
Employee

In your "onopen" event handler it seems you are sending two messages on the websocket in quick succession: one to open the app and one to reload it. You probably have to wait for the open to finish before you can call the reload method.

pramos94
Contributor
Contributor

  ws.onopen = function(e) {
    console.log("Sending to server");
    ws.send(JSON.stringify(openingDoc))
    setTimeout(()=>{
      ws.send(JSON.stringify(doReloading))
    },1000)
  }

 

With this I think you can solve the error.