13 Replies Latest reply: Feb 5, 2016 3:22 PM by Dhara Vaishnav RSS

    Javascript API / get Listbox selection status


      i am using QlikView Workbench 10, Visual Studio 2010 and a Listbox QvObject within my web application.

      I would like to read the current selection status of my Listbox. I understood that i can reach the Listbox object itself by:

      var obj = qva.GetQvObject("LB542");

      According to the Javascript API, the selection is accessible through the GetSelected() method. Can anyone tell me how the correct function call would look like?

      Btw, obj.GetSelected() is neither offered via code completion nor works out ("Object does not support this method"). I am fairly new to Javascript, mainly working with Java.


      Thank you for your help.




        • Javascript API / get Listbox selection status


          Hi Christian!

          I think I know what the problem is but I'll start with some hints since you are new to javascript.

          Instead of using the qva-namespace, try using "this" as much as you can. "this" is a reference to your own object which is the QvaPublic-namespace you can look up in the docs. All the functions and properties below qva is internal and are not documented. Furthermore they can be changed between versions and SR:s so I would suggest you start using the QvaPublic-namespace instead since the members here will not change without notice. Another benefit of using QvaPublic is that you can find examples and hints in the docs which can help you.

          So try using "this.GetQvObject" instead. In this case it does the same thing as calling qva.GetQvObject so you wont notice any difference but it's a good habit to try avoid using qva when there's a member in QvaPublic which can help you.

          When reading the docs you'll see that GetSelected is not a member of the object returned but rather a member on the Data-property on your object. So you should type

          var obj = this.GetQvObject("LB542"); obj.Data.GetSelected()

          to get the array of selected records in the listbox.

          You should be aware of a potential problem with the approach of GetQvObject though - since the loading of objects in QV10 is asynchronously, the object returned from GetQvObject is not guaranteed to be 100% functional. There could be timing issues if you try to use the data on the returned object directly since the listbox can be partially rendered but the data is maybe not completley loaded when your Extension is ready and calls the GetQvObject.

          To avoid this you can do several things, one is to supply a function in the GetQvObject-call as the second parameter. This function is then called upon when the listbox is renderd or updated in any way (e.g. when a selection has occured).


          function test() {
          alert("something happend in the listbox"); }
          this.GetQvObject("LB542", test);

          Then make a selection in the listbox, or just move it a bit to get it to update itself.

          Let me know if you need more help!


            • Javascript API / get Listbox selection status

              Hi Peter & thank you for your reply,

              i see the problem about concurrency. thanks for the warning.

              so i have tried the following:

              <script type="text/javascript">

              function testSelection() {
              var obj = this.GetQvObject("LB542"); // -> "object doesn't support this property or method"
              var test = obj.Data.GetSelected();

              var obj = qva.GetQvObject("LB542"); // -> the object can be seen in the debugger
              var test = obj.Data.GetSelected(); // -> 'Data' is Null or not an object



              <a href="#" onclick="testSelection()">test selection</a>

              I think i this is a visibility problem...

                • Javascript API / get Listbox selection status

                  Oh, my bad. I thought you were building an Extension but it seems you are "injecting" your own javascript in Qlikview. Where do you place this html+javascript, do you load a html-page externally from opendoc.htm or how do you do it?

                  If you don't want to use Extensions you can't use the QvaPublic namespace without some hacks so if you use this approach you'll have to disregard my last answer and revert back to use the qva-namespace. But you should probably not interact with the listbox via GetQvObject if you use the qva-namespace. Depending on what you want to do this approach is not something I would recommend since we don't really support it.

                  With an Extension you can create your own object which in turn can interact with other objects to present data from external sources or just render the QV-data differently from the way standard objects do. You can have a look at some examples of Extensions on http://demo10.qlik.com/ Look for the "Extensions examples" in the featured demos.

                  Do you think Extensions can be of use to you or do you know for a fact that you rather work directly againtst the qva-namespace?


                    • Javascript API / get Listbox selection status

                      Hello Peter,

                      many thanks, this clarifies several things to me.

                      1. QvaPublic is for use in combination with Extensions only. Since we have complex qvw-documents already, rebuilding them in Extensions in order to have a way to communicate with them is not a real option.

                      2. Getting the selection data from a list box inside html is not meant to be done this way, so this explains the difficulties i encountered when trying so.

                      In fact what i want to do is the following: i am looking for a way to get selection data out of listboxes within my .NET webapplication, so that i can process them in other web applications. This could be done via Javascript (see 2.), via server-server-communication with QVS, or via QvObject inside the controller of my MVC webapp. The last two options would be using the qvpx protocol, which doesnt seem to be documented very well. So i am slowly running out of options here.

                      Thank you for your help, again.

                  • Re: Javascript API / get Listbox selection status
                    Tushar Suvarna

                    I peter i am building an extension object which basically selection field in the list box and currently having issue with this piece of code




                    //var object1 =doc.GetObject("LB15",function(){object1.Data.SelectTexts("GA")});


                    The extension script is running in continuous loop i dont know wny