Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
wallerjc
Partner - Contributor III
Partner - Contributor III

setStringValue isn't working?

Hi

I have the following code:

    $("#pivot-button").click(function () {

            app.variable.getByName('vPivotSorting').then(variableModel =>

                variableModel.getLayout().then(variableLayout =>

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

                    console.log(variableLayout.qString);

              }); 

            })


            app.variable.setStringValue('vPivotString', 'dumbTest');


            app.variable.getByName('vPivotSorting').then(variableModel =>

                variableModel.getLayout().then(variableLayout =>

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

                    console.log(variableLayout.qString);


                    app.variable.setStringValue('vPivotString', '2');

              }); 

            })

        });

This is three 'sections' of code, the first gets the string value of a variable, and prints it to console.

The second bit sets the string value to 'dumbTest'

and the third prints it again.

The setStringValue method isn't working though, I can see no evidence it's been set, and it's not returning any errors.

I'm new to javascript, is there something I'm missing here?

thanks,

James.

To confirm, NO string is ever set it simply remains it's default which is set in the app script level.

1 Solution

Accepted Solutions
ErikWetterberg

Hi,

Not sure this helps, but you would need to wait for setStringValue:

app.variable.setStringValue('vPivotString', 'dumbTest').then(function(){

    //get the variable value

});


A better solution is probably to use a genericObject with a StringExpression (something like '=vPivotString'). Check here for an example:

If this is in an extension you can just add the qStringExpression to your properties, and you will be notified automatically when the value changes.

Erik Wetterberg

View solution in original post

2 Replies
ErikWetterberg

Hi,

Not sure this helps, but you would need to wait for setStringValue:

app.variable.setStringValue('vPivotString', 'dumbTest').then(function(){

    //get the variable value

});


A better solution is probably to use a genericObject with a StringExpression (something like '=vPivotString'). Check here for an example:

If this is in an extension you can just add the qStringExpression to your properties, and you will be notified automatically when the value changes.

Erik Wetterberg
wallerjc
Partner - Contributor III
Partner - Contributor III
Author

Hi Erik thanks I see you answering a lot of questions.

I did suspect this was me not understanding the promises properly but  think that makes sense.

I'll have a look at waiting for the response of the setStringValue.

Your other solutions aren't great for what I'm using this for, I'm trying to set a variable in the dashboard to change an expression in a chart, so it's already a bit of a bodge job

thanks anyway,

James.