Skip to main content Skip to complementary content

Variable API

Information noteIf you are using Qlik Sense Business or Qlik Sense Enterprise SaaS, see the API documentation at the Qlik (Developer Portal).
Information noteSTABLE.

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 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
};
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
};
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
};
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
};
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.

Information noteThe setNumValue method replaces the setContent method, which was deprecated in version 2.1.
var config = {
	host: 'QSE_domain',
	prefix: '/',
	port: 443,
	isSecure: true
};
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.

Information noteThe setStringValue method replaces the setContent method, which was deprecated in version 2.1.
var config = {
	host: 'QSE_domain',
	prefix: '/',
	port: 443,
	isSecure: true
};
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)');
});

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!