Skip to content

Instantly share code, notes, and snippets.

@mindspank
Created February 2, 2016 21:24
Show Gist options
  • Select an option

  • Save mindspank/c44b5422127b44a98a61 to your computer and use it in GitHub Desktop.

Select an option

Save mindspank/c44b5422127b44a98a61 to your computer and use it in GitHub Desktop.
Creates a measure on the server
const qsocks = require('qsocks');
const fs = require('fs');
/**
* Creating a master measure in Qlik Sense Desktop
*/
const config = {
host: 'usrad-aklprobook',
isSecure: true,
rejectUnauthorized: false,
port: 4747,
ca: fs.readFileSync('C:/ProgramData/Qlik/Sense/Repository/Exported Certificates/.Local Certificates/root.pem'),
cert: fs.readFileSync('C:/ProgramData/Qlik/Sense/Repository/Exported Certificates/.Local Certificates/client.pem'),
key: fs.readFileSync('C:/ProgramData/Qlik/Sense/Repository/Exported Certificates/.Local Certificates/client_key.pem'),
headers: {
'X-Qlik-User': 'UserDirectory=QTSEL;UserId=akl'
}
};
qsocks.Connect(config).then(function(global) {
// Open a document
global.openDoc('2422586d-89ba-4e68-b790-418526bb1079').then(function(app) {
// Creating a measure in the master library
// See this article for the request structure
// http://help.qlik.com/sense/2.1/en-us/developer/Subsystems/EngineAPI/Content/Classes/AppClass/App-class-CreateMeasure-method.htm
app.createMeasure({
qInfo: {
qId: '',
qType: 'measure'
},
qMeasure: {
qLabel: 'This is a measure created with the Engine API',
qDef: '=Sum(Expression1)'
},
qMetaDef: {
title: 'This is a measure created with the Engine API',
description: 'A description'
}
})
.then(function() {
// Persist changes to disk.
return app.doSave();
});
});
}).catch(function(error) {
console.log(error)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment