Variable API
This API is reliable and breaking changes are unlikely.
qlik.app.variable
The Variable API is the external interface to Qlik Sense variables.
Version history
Each method and property contain information around when it was introduced, updated, deprecated or removed. A list of all relevant API changes per version release can be found in API version history.
Version state | Details |
---|---|
Introduced | 1.0 |
Updated | 2.1 |
Getting started
You must first connect to the Qlik Sense app, and you do this with the qlik.openApp method. You can then use the qlik.app.variable.get method to get an existing variable.
var config = {
host: 'QSE_domain',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: 'web-integration-id-here' //only needed for SaaS editions
};
require(["js/qlik"], function(qlik) {
//open the app
var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config);
//get an existing variable
app.variable.get('yTgsRI').then(function(model){
myvar = model;
});
});
Examples of use
Learn what you can do with the Variable API.
Create a new variable
Use the qlik.app.variable.create method to create a new variable.
var config = {
host: 'QSE_domain',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: 'web-integration-id-here' //only needed for SaaS editions
};
require(["js/qlik"], function(qlik) {
//open the app
var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config);
//create a new variable
app.variable.create({
qName : 'myvar',
qDefinition : 'Month'
});
});
Create a session variable
You can also create a variable that only exists in the session. To do so, use the qlik.app.variable.createSessionVariable method.
var config = {
host: 'QSE_domain',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: 'web-integration-id-here' //only needed for SaaS editions
};
require(["js/qlik"], function(qlik) {
//open the app
var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config);
//create a new session variable
app.variable.createSessionVariable({
qName : 'myvar',
qDefinition : 'Month'
});
});
Get the variable content
Use the qlik.app.variable.getContent method to get the variable content.
var config = {
host: 'QSE_domain',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: 'web-integration-id-here' //only needed for SaaS editions
};
require(["js/qlik"], function(qlik) {
//open the app
var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config);
//get the variable content
app.variable.getContent('MYVAR',function ( reply ){
alert( JSON.stringify( reply ) );
});
});
Set a numeric value
Use the qlik.app.variable.setNumValue method to set a numeric variable value.
var config = {
host: 'QSE_domain',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: 'web-integration-id-here' //only needed for SaaS editions
};
require(["js/qlik"], function(qlik) {
//open the app
var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config);
//set numeric value
app.variable.setNumValue('MYVAR',5);
});
Set a string value
Use the qlik.app.variable.setStringValue method to assign a string value.
var config = {
host: 'QSE_domain',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: 'web-integration-id-here' //only needed for SaaS editions
};
require(["js/qlik"], function(qlik) {
//open the app
var app = qlik.openApp('c31e2aba-3b46-4b13-8b87-c5c2514dea1d', config);
//set string value
app.variable.setStringValue('MYVAR','=(1+1)');
});