Variable API

Note: STABLE.
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

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: window.location.hostname,
	prefix: prefix,
	port: window.location.port,
	isSecure: window.location.protocol === "https:"
};
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;
  });
});

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.

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: window.location.hostname,
	prefix: prefix,
	port: window.location.port,
	isSecure: window.location.protocol === "https:"
};
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: window.location.hostname,
	prefix: prefix,
	port: window.location.port,
	isSecure: window.location.protocol === "https:"
};
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: window.location.hostname,
	prefix: prefix,
	port: window.location.port,
	isSecure: window.location.protocol === "https:"
};
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.

Note: The setNumValue method replaces the setContent method, which was deprecated in version 2.1.
var config = {
	host: window.location.hostname,
	prefix: prefix,
	port: window.location.port,
	isSecure: window.location.protocol === "https:"
};
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.

Note: The setStringValue method replaces the setContent method, which was deprecated in version 2.1.
var config = {
	host: window.location.hostname,
	prefix: prefix,
	port: window.location.port,
	isSecure: window.location.protocol === "https:"
};
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 information help you?

Can you tell us why it did not help you and how we can improve it?