Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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.