Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

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!

1 Solution

Accepted Solutions
filip_tinglof84
Partner - Contributor III
Partner - Contributor III

Hi,

Instead of calling getContent I made a function called getContent ^^.

The only thing it does is creating a table with one dummy dimension and one measure (the variable).

It places the value in an array.

function getContent() {

app.createCube({

  "qDimensions": [{

    "qDef": {

      "qFieldDefs" : ["Dummy"]

  }

  }],

  "qMeasures": [{

    "qDef": {

      "qDef": "=$(vVariable)",

      "qLabel": "Variable"

  }

  }],

  "qInitialDataFetch": [{

    qHeight:1,

    qWidth: 2

  }]

}, function(reply) {

 

$.each(reply.qHyperCube.qDataPages[0].qMatrix, function(index, value) {


var valueArrayText = [];

        valueArrayText = this[1].qText;

        //Do something with the valueArrayText  


});


});


}

View solution in original post

13 Replies
Anonymous
Not applicable
Author

Hey Max!

I'm having the same problem you described. I'm trying to work out this issue for quite some time now but didn't find a suitable solution yet...

I've started thinking this is some kind of Qlik issue or did someone else find a solution yet?

Benbassou
Partner - Contributor III
Partner - Contributor III

Hi,

I had the same problem, did you find a solution to this issue ?

thank you

Anonymous
Not applicable
Author

Hi!

No, haven't found one yet.

andyjalexlive
Contributor III
Contributor III

Hi Max,

I have the same issue, seems like a bug. Anyone found a solution yet?

Best


Andy

filip_tinglof84
Partner - Contributor III
Partner - Contributor III

I have the same issue. I'm currently working on an extension where I want to feed Qlik with a value setContent and get the results string back from a variable using getContent. getContent only returns the default value, not the updated one.

filip_tinglof84
Partner - Contributor III
Partner - Contributor III

I solved it by using a hypercube instead

Anonymous
Not applicable
Author

You already have the value in the javascript variable varValue which you use the set the Qlik variable, so I am curious why you wish to retrieve the value using Qlik getContent() method into a javascript variable when you already have the value in the javascript variable varValue

andyjalexlive
Contributor III
Contributor III

HI Bill

My case case it's so i can create page state

1) getContent gets the initial value of the variable var1

2) a button click event then changes the value of the variable var1 

3) the user navigates away from the page

4) then i want to call getContent again to get the updated value of var1 for when/if user navigates back to the first page

Hope that makes sense

Andy

Anonymous
Not applicable
Author

Hi Filip!

Could you please give me a small example on how to do it with a hypercube?

This would help me a lot!

Thanks.

Kind regards