Last active
April 15, 2016 20:41
-
-
Save mindspank/d115454a4190aaa77ff4379e91501ce0 to your computer and use it in GitHub Desktop.
Change Script in Published app
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
const qsocks = require('qsocks'); | |
const fs = require('fs'); | |
// Our Qlik Sense Certificates | |
const client = fs.readFileSync('C:\\ProgramData\\Qlik\\Sense\\Repository\\Exported Certificates\\.Local Certificates\\client.pem'); | |
const client_key = fs.readFileSync('C:\\ProgramData\\Qlik\\Sense\\Repository\\Exported Certificates\\.Local Certificates\\client_key.pem'); | |
const config = { | |
host: 'localhost', | |
port: 4747, // Standard Engine port | |
isSecure: true, | |
headers: { | |
'X-Qlik-User': 'UserDirectory=Internal;UserId=sa_repository' // Passing a user to QIX to authenticate as | |
}, | |
key: client_key, | |
cert: client, | |
rejectUnauthorized: false, // Don't reject self-signed certs | |
appname: '0caa24a6-4c7c-4915-8dc8-e42f3e10dfe6' // The app GUID we are going to be conneting to | |
}; | |
qsocks.Connect(config).then(function(global) { | |
// Access to the global class | |
// Open document - Here we open the doc without data to not overload the server. | |
// http://help.qlik.com/en-US/sense-developer/2.2/Subsystems/EngineAPI/Content/Classes/GlobalClass/Global-class-OpenDoc-method.htm | |
return global.openDoc(config.appname, '', '', '', true); | |
}) | |
.then(function(app) { | |
// Access to the app class. | |
// http://help.qlik.com/en-US/sense-developer/2.2/Subsystems/EngineAPI/Content/Classes/AppClass/App-class.htm | |
// Our new load script | |
var newScript = "Characters:\r\nLoad Chr(RecNo()+Ord('A')-1) as Alpha, RecNo() as Num autogenerate 26;"; | |
// Return a empty localized script | |
return app.getEmptyScript('Main').then(function(result) { | |
// Set the new loadscript, reload and save. | |
return app.setScript(result + newScript) | |
.then(function() { | |
return app.doReload(); | |
}) | |
.then(function() { | |
return app.doSave(); | |
}) | |
}) | |
}) | |
.catch(function(err) { | |
console.log(err) // Handle error | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment