Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

pritamb89
Contributor

Button Extension to create variable and change content if variable already exist

I am trying to create a Button Extension to create a variable with a value and if the variable already exist then it will change the content. So far I am succeeded to create the variable but not able to change its content. Please check the code below. Need help

define( [ "qlik",

"jquery"

],

function ( qlik) {

function createvar(){

            var app= qlik.currApp();

if(app.variable.getByName( 'testvar' )){

app.variable.getByName( 'testvar' )

.then(

function (app) {

app.variable.setStringValue('testvar' , '12345');

//variable already exist

},

function (errorObject) {

//create variable

app.variable.create({

qName : 'testvar',

    qDefinition : '170'

});

} );

}

    }

return {

support : {

snapshot: true,

export: true,

exportData : false

},

paint: function ($element,layout) {

$element.empty();

var $msg = $( document.createElement( 'Button' ) );

//alert(layout);

$msg.html( 'Set Variable' );

$msg.click( createvar );

$element.append( $msg );

}

};

} );

Tags (2)
Community Browser