Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
dhdezrino
Partner - Contributor II
Partner - Contributor II

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.

_jespers_
Partner - Creator II
Partner - Creator II

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?

Aiham_Azmeh
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

_jespers_
Partner - Creator II
Partner - Creator II

Hi Aiham,

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

Aiham_Azmeh
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.

_jespers_
Partner - Creator II
Partner - Creator II

Ok, thank you for the explanation