Get started with the Variable API
qlik-embed: Where possible, use qlik-embed and qlik/api rather than this framework.
The Variable API is the external interface to Qlik Sense variables.
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.
const config = {
host: '<TENANT_URL>',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: '<WEB_INTEGRATION_ID>'
};
require(["js/qlik"], (qlik) => {
//open the app
const app = qlik.openApp('<APP_ID>', config);
//get an existing variable
app.variable.get('yTgsRI').then((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.
const config = {
host: '<TENANT_URL>',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: '<WEB_INTEGRATION_ID>'
};
require(["js/qlik"], (qlik) => {
//open the app
const app = qlik.openApp('<APP_ID>', 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.
const config = {
host: '<TENANT_URL>',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: '<WEB_INTEGRATION_ID>'
};
require(["js/qlik"], (qlik) => {
//open the app
const app = qlik.openApp('<APP_ID>', 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.
const config = {
host: '<TENANT_URL>',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: '<WEB_INTEGRATION_ID>'
};
require(["js/qlik"], (qlik) => {
//open the app
const app = qlik.openApp('<APP_ID>', 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 deprecated setContent
method.
const config = {
host: '<TENANT_URL>',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: '<WEB_INTEGRATION_ID>'
};
require(["js/qlik"], (qlik) => {
//open the app
const app = qlik.openApp('<APP_ID>', 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 deprecated setContent
method.
const config = {
host: '<TENANT_URL>',
prefix: '/',
port: 443,
isSecure: true,
webIntegrationId: '<WEB_INTEGRATION_ID>'
};
require(["js/qlik"], (qlik) => {
//open the app
const app = qlik.openApp('<APP_ID>', config);
//set string value
app.variable.setStringValue('MYVAR','=(1+1)');
});