Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

juergenschiemann
New 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
Highlighted
erik_wetterberg
Honored Contributor

Re: Cannot access the selections array of a Selection State Object

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.

Erik Wetterberg
https://extendingqlik.upper88.com/
2 Replies
Highlighted
erik_wetterberg
Honored Contributor

Re: Cannot access the selections array of a Selection State Object

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.

Erik Wetterberg
https://extendingqlik.upper88.com/
juergenschiemann
New Contributor

Re: Cannot access the selections array of a Selection State Object

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