Qlik Community

Integration, Extension & APIs

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

Announcements
Customer & Partners, DEC. 9, 11 AM ET: Qlik Product & Strategy Roadmap Session: Data Analytics REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
dhdezrino
Partner
Partner

Get variable value after setting it?

Hello people,

How can I get the variable value after setting it using app.variable.setStringValue?

It doesn't seem to change using app.variable.getByName or app.variable.getContent (Maybe I'm using them wrong)
I'm making a button that can set and unset a variable or filter in a field, but I cant seem to retrieve the variable to carry the pressed style over the next page

Thank you

7 Replies
nikoskavroulaki
Contributor II
Contributor II

Any hints as to what is the solution?

I am facing the same issue.

jesper_snihs
Partner
Partner

Hi,

Is this maybe something that you are after?

qix.app.getVariableByName("variableName").then(function(variable){

    variable.getLayout().then(function(variableLayout) {

        console.log("variableLayout", variableLayout);

    });

});

nikoskavroulaki
Contributor II
Contributor II

I use this code to get the variable val

        var app = qlik.currApp(this);

        var qix = this.backendApi.model.enigmaModel.session;

        var numericValue;

        qix.app.getVariableByName('vTestMode').then(function (variable) {

            variable.getLayout().then(function (variableLayout) {

                numericValue = variableLayout.qNum;

            });

        });

but i seem to get Cannot read property 'model' of undefined error?

aaz
Employee
Employee

Hi nikoskavroulakis‌,

You shouldn't use unsupported method - those may/will change over time, instead use the Variable API ‒ Qlik Sense Developers

let app = qlik.currApp(this); 

let numericValue; 

app.variable.getByName('vTestMode').then(variableModel => {

     variableModel.getLayout().then(variable => {

          numericValue = variableLayout.qNum; 

     });

});

I hope this helps

jesper_snihs
Partner
Partner

Hi Aiham,

Isn't the Qlik Engine API supported, or why isn't my suggestion a way to go?

aaz
Employee
Employee

The enigmaModel is not documented/supported and may change, the engine API is supported, but they are not the same, some enigma methods are mixins that make data transformation.

so for example (not likely to change but anyway as an example), getVariableName may change from returning a model to actually return the variable result, which can break your extensions.

jesper_snihs
Partner
Partner

Ok, thank you for the explanation