Qlik Community

Ask a Question

Integration, Extension & APIs

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

Announcements
Become an analytics expert with Qlik's new 15 week course: Applied Data Analytics using Qlik Sense. READ MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
bill_markham

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
jesper_snihs
Partner
Partner

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