Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
warfollowmy_ver
Creator III
Creator III

How to get the value of a variable in a variable JS?

I do not understand how to retrieve the value of a variable in a global variable JS.

Help me please.

Qv.AddExtension('Test', function () {

    

    var var1;

    var doc = Qv.GetCurrentDocument();

    doc.GetAllVariables(function (vars) {

            for (var i = 0; i < vars.length; i++) {

                if (vars.name === "var1") {

                    var1 = vars.value;

                 break;

              };

       }      

    });

    alert(var1); \\undefined

  

});

1 Reply
ThomasGorr
Partner - Contributor III
Partner - Contributor III

It looks like doc.GetAllVariables is an async function. That means, that your alert(var1) is executed before doc.GetAllVariables() has finished. You need to wait for that function to be finished. Please take a look at Javascript Promises.