Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
juergenschiemann
Contributor
Contributor

Cannot access the selections array of a Selection State Object

Dear community,

I'm trying to make use of the Selection API and retrieve all applied selections on every field in an array. By means of the selectionState() method I was able to get the selections array through:

selState = app.selectionState();

console.log(selState.selections);

The result in the console is as follows:

SelectionState.JPG

Now, when I try to access the first element of the array with selState.selections[0] I'm getting an "undefined" error. Hence, I'm wondering how else I can access the particular elements of that selection array. Can it be that there are certain getter methods for this type of array/object?

Thanks,
Juergen

Labels (2)
1 Solution

Accepted Solutions
ErikWetterberg

Hi,

this is a timing problem. When you call the selectionState() method you will get an object back and the API will request the data from the QIX engine. It will also keep the selectionstate up to date. To be notified when the selections are available use the onData listener, as described here:

https://help.qlik.com/en-US/sense-developer/November2018/Subsystems/APIs/Content/Sense_ClientAPIs/Ca...

 

That fact that it looks OK in the console is because the console checks the state of the object when you expandit, not when the message is printed.

View solution in original post

2 Replies
ErikWetterberg

Hi,

this is a timing problem. When you call the selectionState() method you will get an object back and the API will request the data from the QIX engine. It will also keep the selectionstate up to date. To be notified when the selections are available use the onData listener, as described here:

https://help.qlik.com/en-US/sense-developer/November2018/Subsystems/APIs/Content/Sense_ClientAPIs/Ca...

 

That fact that it looks OK in the console is because the console checks the state of the object when you expandit, not when the message is printed.

juergenschiemann
Contributor
Contributor
Author

Many thanks, Erik, this guided me in the right direction and I've learned something in addition.