Last active
June 21, 2017 19:29
-
-
Save gsbeaton/2dd8ba8a73d0d2c841ad03b9b891b220 to your computer and use it in GitHub Desktop.
A quick and dirty Node.js script to dump QlikSense variables out to a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
| ------------------------------------------------------------------- | |
| A node.js script to write your app variables to file | |
| ------------------------------------------------------------------- | |
| | |
| | |
*/ | |
const serializeapp = require('serializeapp'); | |
const enigma = require('enigma.js'); | |
const WebSocket = require('ws'); | |
const fs = require('fs'); | |
/* | |
| ------------------------------------------------------------------- | |
| USER CONFIGURABLE VARIABLES | |
| ------------------------------------------------------------------- | |
| | |
| Update with the path to your QVF. | |
*/ | |
var settings = {filePath: 'C:\\Users\\george\\Documents\\Qlik\\Sense\\Apps\\' | |
,qvf : 'TitanicDiscovery'}; | |
/* | |
| ------------------------------------------------------------------- | |
| Initialise Enigma | |
| ------------------------------------------------------------------- | |
| Initialise Enigma, serialze app, then save only the variables to | |
| file. | |
| | |
*/ | |
enigma.getService('qix', { | |
schema: require('./node_modules/enigma.js/schemas/qix/3.2/schema.json'), | |
session: { | |
host: 'localhost', | |
port: 4848, | |
secure: false | |
}, | |
createSocket: (url) => new WebSocket(url) | |
}) | |
.then(qix => qix.global.openDoc(settings.qvf+'.qvf')) //TitanicDiscovery | |
.then(app => serializeapp(app)) | |
.then(result => update(result.variables, function(r){ | |
console.log(r); | |
process.exit(-1) | |
}) | |
); | |
/* | |
| ------------------------------------------------------------------- | |
| Update File | |
| ------------------------------------------------------------------- | |
| A basic function using the filesystem library to write the | |
| data to file. | |
| | |
*/ | |
var update = function(data, callback){ | |
//loop through the data to pull out the variables and thier values | |
text = 'Name, Value \n'; | |
for(i=0; i < data.length; i++){ | |
text += data[i].qName; | |
text += ', '; | |
text += '"' + data[i].qDefinition + '"\n'; | |
} | |
fs.writeFile( | |
settings.filePath + settings.qvf + '.csv' //save the new file | |
, text | |
, function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
response = {message: 'The file was written successfully.', success: true}; | |
callback(response); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment