Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
jerryyang756
Creator
Creator

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 );

}

};

} );

0 Replies