Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Get variable value

Hi,

Does anybody know a good, non deprecated, way in an extension to get the value of a Qlik Sense variable into a Javascript variable  ?

2 Replies
_jespers_
Partner - Creator II
Partner - Creator II

Do you mean something like this?

define( [

        "qlik",

        "text!./template.html"

    ],

    function ( qlik, template ) {

        var app = qlik.currApp(this);

        return {

            template: template,

            support: {

                snapshot: true,

                export: true,

                exportData: false

            },

            paint: function () {

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

                var numericValue;

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

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

                        numericValue = variableLayout.qNum;

                    });

                });

                return qlik.Promise.resolve();

            },

            controller: ['$scope', function ( $scope ) {

            }]

        };

    } );

ErikWetterberg

Hi,

If your extension should be snapshottable, you should make sure the variable value is in the layout, something like this (haven't actually tested this code, so there might be syntax errors):

initialProperties:{

  myVar:{

        qStringExpression: '="vBill"'

  }

}

Or you could use qValueExpression.

You could also use the api's, but then you would have problems with snapshots: it might not work at all, or if it does does you would get the value when the snapshot is shown, not when it was taken.

Hope this helps

Erik Wetterberg