Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
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
});
});
}
Thank you very much, Filip!
Hi, Filip
I have a similar issue and tried your getContent() method, but still not working.
Below is the link of my posted thread, could you help me where I am doing wrong?
Thx in advance.
ZZ
Hi, thanks for this - I am trying to implement this but whenever I call this function I get "undefined" in the console. I am not too sure what I am doing wrong.....I am not great with Javascript.
In your code where you say "//Do something with the valueArrayText " am I supposed to do something here to make this function output a result ??
Any help is greatly appreciated !
Thanks