1 Reply Latest reply: Jan 9, 2018 8:44 AM by Oskar Herz RSS

    Qlik Sense: app.variable.getContent() doesn't return the current variable value

    Max Mustermann

      Hi all!

      I'm developing a Qlik Sense extension which should set the value of a variable according to a button click.The extension should then read the new updated value of the same variable.I'm using the variable api.

      The setting of the variable's value works fine, the new updated value is being displayed correctly in (e.g.) a table, but when I try to access to the variable's value inside the javascript code of my extension I always receive the value that has been set by the very first button click. If I reload the app in the browser then the whole behavior starts from the beginning again.

       

      In other words:

      Clicking the button for the first time sets the variable successfully to "1". When I try to get the variable's value it returns me the value "1".

      Clicking the button for the second time sets the variable successfully to "2". Getting the variable's value still returns "1".

      Clicking the button for the third time sets the variable successfully to "3". Getting the variable's value still returns "1".

      And so on...

       

      Here is my current code:

       

      app.variable.setStringValue("SampleVariable",varValue).then(()=>{

            app.variable.getContent('SampleVariable',function ( reply ) {

                 console.log(JSON.stringify( reply ) );

            } );

      });

       

      I've tried the same by using the following code but it produces exactly the same incorrect behavior:

       

      app.variable.setStringValue("SampleVariable, varValue)

            .then(() => {

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

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

                                     console.log("variableLayout: " + JSON.stringify(variableLayout));

                              });

             });

      });

       

      Thank you for reading!