Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
swapnil_kumbhar
Partner - Contributor III
Partner - Contributor III

how to execute Nodejs javascript code through Qlik sense Extesion

Hi All,

I have javascript code running on Nodejs. Now i want to execute it from Qlik sense Extension.

Is there any way we can embed Nodejs code in Qlik sense extension?

Please help

Regards,

Swapnil

5 Replies
Vincenzo_Esposito

QlikSense Extension code run on the client browser, whereas the Node.Js code typically run on server, in the backend. You can interact with the backend code for instance through a REST API call

swapnil_kumbhar
Partner - Contributor III
Partner - Contributor III
Author

Hi Vincenzo,

Thanks for reply.

Is there any way we can execute Nodejs code by creating Button object in Qlik Sense Extension & On click of that button we can execute the NodeJs code.

Also Is there any way to integrate the Nodejs webserver in Qlik sense(Like IIS) to execute the Nodejs code.

Regards,

Swapnil

Vincenzo_Esposito

Can you explain what does the NodeJs code actually do and where it is located?

swapnil_kumbhar
Partner - Contributor III
Partner - Contributor III
Author

Hi Vincenzo,

The Nodejs code & Qlik sense server are located on same machine.

Using Nodejs code to:

1. Connect to Qlik sense API's

2. Authenticate to Qlik using Certificate

3. Create App & Stream

4. Load data into app

5. Publish app to stream created

Currently we are able to execute above steps from Nodejs Command Prompt.

We  are looking for Solution or some Techniques through which we can execute Nodejs Javascript code from Browser or Qlik extension.

We have tried executing code using Browserify but we are getting Certificate related issue.

Below is Sample code we have used:

//Sample.js

var qsocks = require('qsocks');

var fs = require('fs');

var request = require('request');

var https=require('https');

var User = "LoginUserName";

var Token = "";

var AppId = "";

//Set our request defaults, ignore unauthorized cert warnings as default QS certs are self-signed.

var requestDefaults = request.defaults({

rejectUnauthorized: false,

host: 'Hostname',//'Hostname',

pfx: fs.readFileSync("client.pfx")

});

//Authenticate whatever user you want

var auth_user = JSON.stringify({

"UserDirectory": 'Hostname',

"UserId": 'Username',

"Attributes": []

});

getTicket();

// Get Ticket Function : To Connect to Proxy API for authentication & Create app

function getTicket(){

//Get ticket for user

requestDefaults.post({

uri: 'https://Hostname:4243/qps/ticket?xrfkey=abcdefghijklmnop',

body: auth_user,

headers:{

'x-qlik-xrfkey': 'abcdefghijklmnop',

'content-type': 'application/json'

}

},

function(err, res, body) {

//Consume ticket, set cookie response in our upgrade header against the proxy.

var ticket = JSON.parse(body)['Ticket'];

requestDefaults.get( 'https://Hostname/hub/?qlikTicket=' + ticket,

function(error, response, body)

{

var cookies = response.headers['set-cookie'];

//qsocks config, merges into standard https/http object headers.

//Set the session cookie correctly.

var config ={

host: 'Hostname/app/',

isSecure: true,

origin: 'http://localhost',

rejectUnauthorized: false,

headers:{

"Content-Type": "application/json",

"Cookie": cookies[0]

}

};

console.log('Get Ticket Connecting');

qsocks.Connect(config).then(function(global)

{

console.log(User)

console.log('Create App');

global.createApp(User, 'First Script Tab')

.then(() => {

// Close our connection.

return global.connection.close();

})

.catch( err => {

// Failed to create app. In Desktop application names are unique.

console.log( err )

})

console.log('Create App done!');

})

.then(() => {

console.log('Get Ticket Done!')

//createStream();

})

})

});

}

Regards,

Swapnil

Vincenzo_Esposito

You're getting over complicating simple thinks. Have a look to the widgets. http://help.qlik.com/en-US/sense-developer/September2017/Subsystems/Extensions/Content/widgets-intro...

As far as I remember the snippet example code already has the case you want to use