Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Javascript API / get Listbox selection status

Hello,

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.

1 Solution

Accepted Solutions
Not applicable
Author

If the only thing you would like to do is get the selections, then qva.GetQvObject could be the best way after all.

function test(){
alert("Selections: " + this.Data.GetSelected());
}
qva.GetQvObject("LB542", test, this);




Try this and let me know what you think?

/Peter

View solution in original post

13 Replies
Not applicable
Author

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).

Example:


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!

/Peter



Not applicable
Author

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

}

</script>

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

I think i this is a visibility problem...

Not applicable
Author

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?

/Peter

Not applicable
Author

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.

Not applicable
Author

If the only thing you would like to do is get the selections, then qva.GetQvObject could be the best way after all.

function test(){
alert("Selections: " + this.Data.GetSelected());
}
qva.GetQvObject("LB542", test, this);




Try this and let me know what you think?

/Peter

Not applicable
Author

Dear Peter,

that just did it! Many thanks!

Christian

Not applicable
Author

Is there a way in the page javascript to bind to qva events - for instance, I would like to be alerted in Javascript every time an ajax call is completed. I see that there is qva.Doc object which has events like ondataavailable. Is it possible to bind to them?

Not applicable
Author

Hi,

is there a reference doc or a way to expose the methods and properties of the qva javascript? I can't find documentation that helps me understand statements like...

qva.Set("Document.LB55.ULC", "action", "", false);

qva.Set(







"LB55", "text", val, false);

qva.Set(



"Document.LB55.LOC","action","",false);

Currently using QV 9 SR3 on server and desktop. Any help is greatly appreciated.





Not applicable
Author

Hi Jeffrey,

I have struggled with the same problem and there should be an own reference document for JScript really (because it's supported)... 😐

Here's some example at start (and sorry that I don't know the solution about how to get active selection with Jscript) AND it really works with the Jscript

//Create listbox object

var sLB1 = Application.ActiveDocument().GetSheetObject("LB01");

//Get e.g. the first listbox value from the first "0" row and the first "0" column 

var sGetFirstCellValue = sLB1.GetCell(0,0);

//Print value in the msgbox

Application.MsgBox(sGetFirstCellValue.Text);

==================================

Here's how you can get the active ListBox selection in the InputField (AND via UI):

1. Create button.

2. Select Actions -tab via Button Properties popup.

3. Select Set Variable action.

4. Select target attribute for value collection.

5. Write the value below in the Value field.

=GetFieldSelections([Package Name])

Hopefully these examples helped even a bit... 😐