10 Replies Latest reply: Jul 10, 2012 5:10 AM by Alexander Karlsson RSS

    Read QV-Variables via JavaScript

    Lars Bayer

      Hello everybody,

      my problem is: if I define a variable in the desktop client (for instance: vTest = localTime()) i'm not able to access the interpreted content of that variable in the Ajax-client. I just can read "localTime()" as a String from the VariableMgr. The idea is to send the function-name "localTime()" to the QV-Server via Ajax (or to use the QMS-WebService API) and get the interpreted value as a response. Is that possible? Or even better: I send the name of the variable ("vTest") to the QV-Server and get the calculated content.


      I can't find proper methods in the QMS-API nor "JS-API" :-(

      ->Workaround:  I could define input boxes dynamically via JS, access it, get the calculated content and remove the input box, but it's way too slow!


      Can anybody help me out here?


      Thanks in advance,


        • Read QV-Variables via JavaScript
          Jonathan Dienst



          If you put a leading = in the variable definition, you should get the interpreted value in both Ajax and the local client. You can do this in the variable dialog, and in script you would say:


          Set vTest = =localtime();  // that's not a misprint


          Then use it in expressions as $(vTest) or '$(vTest)'.


          Hope that helps


            • Read QV-Variables via JavaScript
              Lars Bayer

              Hello Jonathan,


              thanks for your reply!


              Unfortunately it's not working. Let me explain you my intention in more detail:


              I am able to define variables and I can use them in expressions. But I can't use them in the JS-Code of an extension object. In pseudo-code i want to do sth like this:


              Qva.AddExtension(..., function(){

                   var vTest = QlikView.giveMeTheInterpretedVariable("vTest");

                   alert(vTest); // displays "08.05.2012 09:43:45"



              Is there a functionality like this? Or some workaround?


              Thanks + best regards,


                • Read QV-Variables via JavaScript
                  Erik Wetterberg

                  Hi Lars,

                  One way is to use the Text tag in your Definition.xml:

                  <Text Label="Variable:" Initial=""/>


                  In the property dialog, set it up like '=vTest'.

                  You extension will get the value in Layout.Text0.text (if it is your fist Text tag).


                  Alternatively you can set the variable name in the Definition.xml:

                  <Text Label="Variable:" Initial="" Expression="=vTest"/>


                  There is also a javascript call to get all variables:



                  where callback is a javascript function to handle the result.



              • Re: Read QV-Variables via JavaScript
                Lars Bayer

                Hi Eric (and everyone else),


                at the first moment that solution seemed to work. But now it's not working anymore :-(
                Is it possible that this is a bug in QV11SR1 (can't imagine though)?


                My Steps once more in detail:


                I have a QVW with the fields YEAR (such as "2012") and MONTH (such as "6").

                I created a variable "vKeyDate" with the definition "=MakeDate(Year,Month)"

                   -> works fine within a textbox or an inputfield (output: "01.06.2012")


                In my Script.js of the extension I created a JS function:


                var doc = Qv.GetCurrentDocument();


                        $.each(data, function(i, object){





                The returned (relevant) object looks like this:

                     isconfig: "false",

                     isnum: "false",

                     isreserved: "false",

                     name: "vKeyDate",

                     text: "",

                     value: "=MakeDate(Year,Month)" // <-- I want this to be interpreted



                Can you confirm that this steps should work in SR1?


                Best Regards,

                  • Re: Read QV-Variables via JavaScript
                    Alexander Karlsson

                    I'm getting the same results.

                      • Re: Read QV-Variables via JavaScript
                        Lars Bayer

                        Hi Alexander,


                        do you think that there is any solution for this? It's really a big problem for us right now :-(
                        I had a small e-mail conversation with Ingemar Carlo last week and he gave me the tip to try the SetOnUpdateComplete Function of the qv-document and call the GetAllVariables function inside. His assumption was that the variables are not yet calculated when they are fetched.


                        But that results in an infinite loop, because the GetVariable function triggers the OnUpdate event of the document.... I fixed it like this:


                        Qva.AddExtension('Variables', function(){

                              var doc = Qv.GetCurrentDocument();

                              var varsRetrieved = false;




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

                                                   alert(variables[i].name + " = " + variables[i].value);



                                        varsRetrieved = true;



                          }, false);


                        But in the end it's still not working, regardless of the moment the variables are fetched.


                        Nachricht geändert durch lars.bayer